From: Roland Schmitt Date: 2006-04-18T18:12:19+09:00 Subject: Re: RSA Encryption Decryption 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 = Certificate.new(File.read("server.cer")) private_key = RSA.new(File.read("server.cer.key")) message = "This is a test!" puts("--- Start private key encryption / public key decryption") crypt = 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 = cert.public_key.public_encrypt(message) puts("Encrypted text------") puts(crypt) puts("Decryted text-------") puts(private_key.private_decrypt(crypt)) Regards, Roland