Skip to content

Instantly share code, notes, and snippets.

@capoferro
Created November 12, 2010 16:02
Show Gist options
  • Select an option

  • Save capoferro/674264 to your computer and use it in GitHub Desktop.

Select an option

Save capoferro/674264 to your computer and use it in GitHub Desktop.
Straight AES encrypt/decrypt
def encrypt_bugdb_password
if !(self.bugdb_password_changed? or self.new_record?)
return
end
cipher = OpenSSL::Cipher::Cipher.new CipherHelper::encryption_type
cipher.encrypt
cipher.key = Digest::SHA1.hexdigest CipherHelper::key
cipher.iv = self.initialization_vector = cipher.random_iv
encrypted_password = cipher.update self.bugdb_password
encrypted_password << cipher.final
self.bugdb_password = encrypted_password
end
def decrypt_bugdb_password
cipher = OpenSSL::Cipher::Cipher.new CipherHelper::encryption_type
cipher.decrypt
cipher.key = Digest::SHA1.hexdigest CipherHelper::key
cipher.iv = self.initialization_vector
decrypted_password = cipher.update self.bugdb_password
decrypted_password << cipher.final
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment