Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/housing_misc/encrypt_decrypt.rb
Instance Method Summary collapse
Instance Method Details
#decrypt(key = DEFAULT_KEY) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/housing_misc/encrypt_decrypt.rb', line 14 def decrypt(key=DEFAULT_KEY) cipher = OpenSSL::Cipher.new(ENCRYPTION_ALGO).decrypt cipher.key = (Digest::SHA1.hexdigest key)[0...KEY_LENGTH] s = [self].pack("H*").unpack("C*").pack("c*") cipher.update(s) + cipher.final end |
#encrypt(key = DEFAULT_KEY) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/housing_misc/encrypt_decrypt.rb', line 7 def encrypt(key=DEFAULT_KEY) cipher = OpenSSL::Cipher.new(ENCRYPTION_ALGO).encrypt cipher.key = (Digest::SHA1.hexdigest key)[0...KEY_LENGTH] s = cipher.update(self) + cipher.final s.unpack('H*').first end |