Created
May 12, 2014 20:59
-
-
Save deuterium/b0022e5af5e005e506ae to your computer and use it in GitHub Desktop.
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
$key = OpenSSL::Digest::SHA256.new("verysecretkey").digest | |
def decrypt(data) | |
cipher = OpenSSL::Cipher::AES256.new(:CBC) | |
cipher.decrypt | |
cipher.key = $key | |
begin | |
msg = cipher.update(data) | |
msg << cipher.final | |
rescue Exception => e | |
#puts e | |
end | |
return msg | |
end | |
def encrypt(data) | |
cipher = OpenSSL::Cipher::AES256.new(:CBC) | |
cipher.encrypt | |
cipher.key = $key | |
begin | |
payload = cipher.update(data) | |
payload << cipher.final | |
puts payload.bytesize | |
rescue Exception => e | |
#puts e | |
end | |
return payload | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment