2011/11/9 varma .p <pothuri_satish / yahoo.co.in>:
> Thanks Eric....for replying
>
> I want to see:
>
> (encrypted string with the private key ) should equal to the
> (decrypted string with the public key)
>
>
>  
>
>  AAH/////////////////////////////////////////////////////////
> /////////////////wBoZWxsbw== ) = ( hello )
>
> --
> Posted via http://www.ruby-forum.com/.
>
>

Your code says:

>  puts "encrypted string with the private key"
>  puts "#{string}"

>  puts "decrypted string with the public key"
>  puts "#{pt_with_pub}"

where

>  string=Base64.encode64(cipher_text_with_priv);

and

>  pt_with_pub = rsa.public_decrypt(cipher_text_with_priv)

This means string is Base64-encoded, pt_with_pub is not,
that's why you get different results.

You should only use this code if you are experimenting
with RSA, but I would recommend not using it in any
production code. A good rule of thumb is to actually never
use asymmetric encryption unless you are 100% sure that
you need it and are very clear about the reasons why.

If you have doubts about it, always prefer a symmetric
encryption scheme such as AES. OpenSSL::Cipher offers
these symmetric algorithms. They are magnitudes faster and
offer less surfaces for attack.

Regards,
Martin