Created
October 16, 2015 06:59
-
-
Save marshluca/cb36ade46664c8d1312f to your computer and use it in GitHub Desktop.
3 des
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def encrypted_password(password) | |
if password.length < 8 | |
password = "#{password}#{'0'*(8-password.length)}" | |
end | |
key = "12345678" | |
secret = "1234567890" + password + "123456" | |
# des-ede3-cbc Three key triple DES EDE in CBC mode | |
# des-ede3 Three key triple DES EDE in ECB mode | |
# des3 Alias for des-ede3-cbc | |
# des-ede3-cfb Three key triple DES EDE CFB mode | |
# des-ede3-ofb Three key triple DES EDE in OFB mode | |
# http://ruby-doc.org/stdlib-2.0.0/libdoc/openssl/rdoc/OpenSSL/Cipher.html | |
cipher = OpenSSL::Cipher::Cipher.new('des-ede3') | |
cipher.encrypt | |
cipher.iv = key | |
cipher.key = secret | |
cipher.padding = 0 | |
result = cipher.update(password) + cipher.final | |
Base64.encode64(result) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment