module Lingo::Database::Crypter

Constants

CIPHER
KEYLEN

Public Instance Methods

decode(key, val) click to toggle source
# File lib/lingo/database/crypter.rb, line 49
def decode(key, val)
  crypt(:decrypt, key, val, digest(key)).force_encoding(ENCODING)
end
digest(key) click to toggle source
# File lib/lingo/database/crypter.rb, line 41
def digest(key)
  Digest::SHA1.hexdigest(key)
end
encode(key, val) click to toggle source
# File lib/lingo/database/crypter.rb, line 45
def encode(key, val)
  [digest = digest(key), crypt(:encrypt, key, val, digest)]
end

Private Instance Methods

crypt(method, key, val, digest) click to toggle source
# File lib/lingo/database/crypter.rb, line 55
def crypt(method, key, val, digest)
  cipher = OpenSSL::Cipher.new(CIPHER).send(method)
  cipher.iv = cipher.key = digest[0, KEYLEN]
  cipher.update(val) + cipher.final
end