module Lingo::Database::Crypter

Constants

CIPHER
KEYLEN

Public Instance Methods

decode(key, val) click to toggle source
# File lib/lingo/database/crypter.rb, line 50
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 42
def digest(key)
  Digest::SHA1.hexdigest(key)
end
encode(key, val) click to toggle source
# File lib/lingo/database/crypter.rb, line 46
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 56
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