Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/humpass/encrypter.rb
Instance Method Summary collapse
Instance Method Details
#decrypt(key) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/humpass/encrypter.rb', line 12 def decrypt(key) cipher = OpenSSL::Cipher::AES.new(128, :CBC).decrypt cipher.key = Digest::SHA2.hexdigest(key)[0..15] s = [self].pack("H*").unpack("C*").pack("c*") cipher.update(s) + cipher.final end |
#encrypt(key) ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/humpass/encrypter.rb', line 4 def encrypt(key) cipher = OpenSSL::Cipher::AES.new(128, :CBC).encrypt cipher.key = Digest::SHA2.hexdigest(key)[0..15] s = cipher.update(self) + cipher.final s.unpack('H*')[0].upcase end |