Try mine You may use OpenSSL to generate key and use this program to do rsa. It's speed is quite ok for 2048 bit encryption.
Shannon
rsatest.rb (1.91 KB)
···
From: "name pipe" <namepipe@gmail.com>
Reply-To: ruby-talk@ruby-lang.org
To: ruby-talk@ruby-lang.org (ruby-talk ML)
Subject: Re: RSA Encryption Decryption
Date: Tue, 18 Apr 2006 18:34:18 +0900Thanks, 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 <Roland.Schmitt@web.de> 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 = 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
>