Created
November 12, 2010 16:02
-
-
Save capoferro/674264 to your computer and use it in GitHub Desktop.
Straight AES encrypt/decrypt
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 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