Created
November 27, 2013 08:11
-
-
Save rbmrclo/7672241 to your computer and use it in GitHub Desktop.
Obfuscate an id
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 Obfuscate | |
def cipher | |
OpenSSL::Cipher::Cipher.new('aes-256-cbc') | |
end | |
def cipher_key | |
'any string that you want' | |
end | |
def deobfuscate(value) | |
c = cipher.decrypt | |
c.key = Digest::SHA256.digest(cipher_key) | |
c.update(Base64.decode64(value.to_s)) + c.final | |
end | |
def obfuscate(value) | |
c = cipher.encrypt | |
c.key = Digest::SHA256.digest(cipher_key) | |
Base64.encode64(c.update(value.to_s) + c.final).squish | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment