R
Roland Schmitt
Hello,=20
Example:
require "openssl"
include OpenSSL
include Cipher
cipher =3D Cipher.new("AES-256-CBC")
key =3D cipher.random_key()
iv =3D cipher.random_iv()
#---- Encrypt
text =3D "Hello, World!"
cipher.encrypt(key,iv)
cipher.key=3Dkey
cipher.iv =3D iv
e =3D cipher.update(text)
e << cipher.final()
puts("Encrypted text: " + e.to_s())
#---- Decrypt
cipher =3D Cipher.new("AES-256-CBC")
cipher.decrypt(key,iv)
cipher.key =3D key
cipher.iv =3D iv
d =3D cipher.update(e)
d << cipher.final()
puts("Plain text: " + d.to_s())
Hope it helps,
Roland
Yes, it is a sad, sad story...=20-----Urspr=FCngliche Nachricht-----
Von: (e-mail address removed)=20
[mailto:[email protected]] Im Auftrag von Michal Suchanek
Gesendet: Dienstag, 27. September 2005 13:09
An: ruby-talk ML
Betreff: How do I (really) encrypt a string in ruby?
=20
Hello
=20
I find the ruby crypto very confusing. It looks like the=20
methods are dynamically generated, and carry no rdoc=20
documentation that would appear on ruby-doc.
...I tried to look at the openssl samples supplied with ruby.
But they only show how to use a high level method which
Example:
require "openssl"
include OpenSSL
include Cipher
cipher =3D Cipher.new("AES-256-CBC")
key =3D cipher.random_key()
iv =3D cipher.random_iv()
#---- Encrypt
text =3D "Hello, World!"
cipher.encrypt(key,iv)
cipher.key=3Dkey
cipher.iv =3D iv
e =3D cipher.update(text)
e << cipher.final()
puts("Encrypted text: " + e.to_s())
#---- Decrypt
cipher =3D Cipher.new("AES-256-CBC")
cipher.decrypt(key,iv)
cipher.key =3D key
cipher.iv =3D iv
d =3D cipher.update(e)
d << cipher.final()
puts("Plain text: " + d.to_s())
Hope it helps,
Roland