Concept: I want to encrypt a string(hello) should give say xxx(private
key) and again encrypting xxx should give say yyy(public key) and
decrypting yyy should give xxx and decrypting xxx should give my
original string(hello).

Two way process using ruby.

I was tried this using RSA in ruby (as shown below) but it was not
getting my decrypted public key as similar as private key.


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')


I am new to ruby if i am wrong pleae suggest me . can anyone help me
please...............

-- 
Posted via http://www.ruby-forum.com/.