Skip to content

Instantly share code, notes, and snippets.

@marshluca
Created October 16, 2015 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marshluca/cb36ade46664c8d1312f to your computer and use it in GitHub Desktop.
Save marshluca/cb36ade46664c8d1312f to your computer and use it in GitHub Desktop.
3 des
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