Skip to content

Instantly share code, notes, and snippets.

@failshell

failshell/code Secret

Created December 21, 2014 03:43
Show Gist options
  • Save failshell/b93167694187de7ea405 to your computer and use it in GitHub Desktop.
Save failshell/b93167694187de7ea405 to your computer and use it in GitHub Desktop.
def encrypt(plaintext, key)
cipher = OpenSSL::Cipher::AES256.new(:CBC)
cipher.encrypt
cipher.key = File.read(key)
iv = cipher.random_iv
encrypted = cipher.update(plaintext) + cipher.final
puts Base64.encode64("#{Base64.encode64(encrypted)},#{Base64.encode64(iv)}")
puts Base64.encode64("#{Base64.encode64(encrypted)},#{Base64.encode64(iv)}").inspect
end
[failshell@manticore]:titan git:(master) ✗ $ ./bin/titan -k key -e 'some super secret'
OTZGdWtzM01id3pndEJzVlZRTjBKckFsclhzZm9TVElaRHJWc0s4Vm5Udz0K
LHdPdXpoMEdCM3ZvbU45N1pQdGdoYXc9PQo=
"OTZGdWtzM01id3pndEJzVlZRTjBKckFsclhzZm9TVElaRHJWc0s4Vm5Udz0K\nLHdPdXpoMEdCM3ZvbU45N1pQdGdoYXc9PQo=\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment