Last active
May 29, 2017 18:18
-
-
Save pachacamac/f783b2422ad2ad523a9805688095a291 to your computer and use it in GitHub Desktop.
Rails encryption/decryption helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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