Jano Svitok
9/5/2006 5:03:00 AM
On 9/4/06, Jean Verger <jean.verger@gmail.com> wrote:
> Hi all,
> I've been reading in this list about crypting with RSA but I don't get
> it to work.
>
> I beg your help. I believe one of the problems I'm having is that the
> different values (.e , .n , .d ) are being given in decimal format,
> while the java function will need hexaedcimal format.
>
> Please, any hint or idea on how to encrypt/verify based on RSA with
> Ruby? any other library? Or ... how can I create an RSA private key
> based on hexadecimal values of n, e and d? How can I convert decimal
> values to hex?
>
> thanks a lot,
>
> Jean
>
> Some code:
> In the client javascript to encrypt the password (based on www.ohdave.com/rsa)
>
> In the server, the following code:
>
> # key.pem is generated with "openssl genrsa -out key512.pem 512" in the
> # command line
> private_key = PKey::RSA.new(File.open("key.pem").read, nil)
>
> # Crypting with the public, decrypting with the private
> @pwdOriginal = "uno_dos_tres"
> @pwdCrypted_PubPriv = private_key.public_encrypt(@pwdOriginal)
> @pwdDecrypted_PubPriv = private_key.private_decrypt(@pwdCrypted_PubPriv)
>
> # This values are generated out the .pem file
> @f_e = private_key.e
> @f_d = private_key.d.to_s
> @f_n = private_key.n
> @f_public = private_key.public_key
> @f_private = private_key.to_s
Hi,
1. your code seems to work fine (if you fix the file name, add require
'openssl' and include OpenSSL, alternatively prefix Pkey with
OpenSSL::)
2. dec-> hex:
"%x" % 123 #=> "7b"
"%X" % 123 #=> "7B"
3. Just a note: Java and Javascript are two different languages
4. Are you sure you want to send the private key over the wire?
5. The private key has another components besides e,d,n that speed up
the decryption/signature generation significantly.