Skip to content

Instantly share code, notes, and snippets.

@rdp
Created December 21, 2019 05:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rdp/349161fd5b10208dc7445fb5d9beefae to your computer and use it in GitHub Desktop.
Save rdp/349161fd5b10208dc7445fb5d9beefae to your computer and use it in GitHub Desktop.
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