class String

Public Instance Methods

decrypt(key=DEFAULT_KEY) click to toggle source
# 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) click to toggle source
# 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