From: Eric Hodel Date: 2011-11-09T05:47:04+09:00 Subject: Re: ruby encryption & decryption using rsa On Nov 7, 2011, at 11:14 PM, varma potthuri wrote: > require 'openssl' > include OpenSSL > require 'base64' > > class Generatekey > def keygeneration_and_encryption_decryption(txt) > rsa = PKey::RSA.generate(512) > > cipher_text_with_priv = rsa.private_encrypt(txt) > string=Base64.encode64(cipher_text_with_priv); > puts "encrypted string with the private key" > puts "#{string}" > > cipher_text_with_pub = rsa.public_encrypt(txt) > string1=Base64.encode64(cipher_text_with_pub); > puts "encrypted string with the public key " > puts "#{string1}" > > pt_with_pub = rsa.public_decrypt(cipher_text_with_priv) > puts "decrypted string with the public key" > puts "#{pt_with_pub}" > > pt_with_priv = rsa.private_decrypt(cipher_text_with_pub) > puts "decrypted string with the private key" > puts "#{pt_with_priv}" > end > end > generatekey=Generatekey.new > generatekey.keygeneration_and_encryption_decryption('hello') When I run this code I see: $ pbpaste | ruby encrypted string with the private key AAH///////////////////////////////////////////////////////// /////////////////wBoZWxsbw== encrypted string with the public key AAKcp3TykBaaO4/PQ2A6x4k44ve6xkxjtA6ufszclAPW7NwshQOXqqSaLaMc zPOtln6Kx/uMzi4cngBoZWxsbw== decrypted string with the public key hello decrypted string with the private key hello What are you seeing?