Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
require "openssl"
NAME = "Boy"
cipher = OpenSSL::Cipher.new("AES-256-CBC")
cipher.encrypt
key = cipher.random_key
iv = cipher.random_iv
# Username
s2 = IO::Memory.new
s2.write(cipher.update(NAME) )
s2.write(cipher.final)
encrypted_name = s2.to_s
puts encrypted_name
decipher = OpenSSL::Cipher.new("AES-256-CBC")
decipher.decrypt
decipher.key = key
decipher.iv = iv
# Username
s1 = IO::Memory.new
s1.write(decipher.update(encrypted_name))
s1.write(decipher.final)
plain_name = s1.to_s
puts plain_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.