Skip to content

Instantly share code, notes, and snippets.

@deuterium
Created May 12, 2014 20:59
Show Gist options
  • Save deuterium/b0022e5af5e005e506ae to your computer and use it in GitHub Desktop.
Save deuterium/b0022e5af5e005e506ae to your computer and use it in GitHub Desktop.
$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