class QuoVadis::Crypt
Constants
- KEY_LENGTH
- SEPARATOR
Public Class Methods
decrypt(value)
click to toggle source
# File lib/quo_vadis/crypt.rb, line 16 def self.decrypt(value) return nil if value.nil? return '' if value == '' salt, data = value.split SEPARATOR crypt = encryptor key(salt) crypt.decrypt_and_verify(data) end
encrypt(value)
click to toggle source
# File lib/quo_vadis/crypt.rb, line 6 def self.encrypt(value) return nil if value.nil? return '' if value == '' salt = SecureRandom.hex KEY_LENGTH crypt = encryptor key(salt) ciphertext = crypt.encrypt_and_sign value [salt, ciphertext].join SEPARATOR end
Private Class Methods
encryptor(key)
click to toggle source
# File lib/quo_vadis/crypt.rb, line 30 def self.encryptor(key) ActiveSupport::MessageEncryptor.new(key) end
key(salt)
click to toggle source
# File lib/quo_vadis/crypt.rb, line 34 def self.key(salt) ActiveSupport::KeyGenerator.new(secret).generate_key(salt, KEY_LENGTH) end
secret()
click to toggle source
# File lib/quo_vadis/crypt.rb, line 38 def self.secret Rails.application.secret_key_base end