From: name pipe Date: 2006-04-18T18:34:18+09:00 Subject: Re: RSA Encryption Decryption ------=_Part_21873_602701.1145352855244 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Thanks, but its bit confusing with new include files and stuff. Any simple eg. which creates RSA public, private keys and encrypts/decrypts data ? On 4/18/06, Roland Schmitt wrote: > > Hi, > > > name pipe wrote: > > Hi, > > > > I would like to know how can we do encryption and decryption using > public > > and private keys in ruby. Does ruby any RSA libraries for the same. A > small > > example would be quite helpful. > > > > Thanks > > > > take a look at the openssl bindings for ruby: > > require "openssl" > include OpenSSL > include X509 > include PKey > > cert =3D Certificate.new(File.read("server.cer")) > private_key =3D RSA.new(File.read("server.cer.key")) > message =3D "This is a test!" > > puts("--- Start private key encryption / public key decryption") > crypt =3D private_key.private_encrypt(message) > puts("Plain text ---------") > puts(message) > puts("Encrypted text------") > puts(crypt) > puts("Decryted text-------") > puts(cert.public_key.public_decrypt(crypt)) > > puts("--- Start public key encryption / private key decryption") > crypt =3D cert.public_key.public_encrypt(message) > puts("Encrypted text------") > puts(crypt) > puts("Decryted text-------") > puts(private_key.private_decrypt(crypt)) > > > > Regards, > Roland > > ------=_Part_21873_602701.1145352855244--