Skip to content

Instantly share code, notes, and snippets.

@pachacamac
Last active May 29, 2017 18:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pachacamac/f783b2422ad2ad523a9805688095a291 to your computer and use it in GitHub Desktop.
Save pachacamac/f783b2422ad2ad523a9805688095a291 to your computer and use it in GitHub Desktop.
Rails encryption/decryption helper
module Cipher
ENCRYPTOR = ActiveSupport::MessageEncryptor.new(Rails.application.secrets.secret_key_base)
def self.encrypt(data)
ENCRYPTOR.encrypt_and_sign(data)
end
def self.decrypt(data)
ENCRYPTOR.decrypt_and_verify(data)
end
end
# USAGE:
dat = {
did: 993,
dur: 60,
fee: 0.04,
adv: 100000,
cts: 1496080663
}
dat = Cipher.encrypt(dat)
puts "Encrypted: #{dat}"
dat = Cipher.decrypt(dat)
puts "Decrypted: #{dat}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment