From: Alan Fritz Date: 2006-04-21T03:40:06+09:00 Subject: Re: RSA Encryption Decryption Shannon, Your code expects HEX. How are you generating keys in a hex format? Thanks, -Alan -----Original Message----- From: Shannon Fang [mailto:xrfang@hotmail.com] Sent: Thursday, April 20, 2006 8:46 AM To: ruby-talk ML; namepipe@gmail.com Cc: ruby-talk@ruby-lang.org Subject: Re: RSA Encryption Decryption I am sorry that I do not know the "PEM" format. However, it is very easy to use OpenSSL to generate a code for my program. Under Linux command line, you run this command: openssl genrsa 2048 | openssl rsa -text -noout In the output you will see modulus, private key and public key. Remove all the ":" between it, make these a very huge Integer. You are done. If you like, you may write a program to do this too. Hope this helps. Crypto-Experts, welcome to comment on this piece of code, is it important to use "PEM"? Thanks, Shannon >From: "name pipe" >To: xrfang@hotmail.com >Subject: Re: RSA Encryption Decryption >Date: Wed, 19 Apr 2006 18:38:00 +0530 > >Hi Shannon, > >Your code was helpful. Thanks. >Only problem is that the pub/private keys you used in the code are not in >PEM format. How can we generate keys in the format you have used in the >code. Also I need to make a 32 bit key. How can I do that ? > >Thanks. > > >On 4/18/06, Shannon Fang wrote: > > > > 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 > > > > > > >From: "name pipe" > > >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 +0900 > > > > > >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 = 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 > > > > > > > > > > > > > > > >