Problems with OpenSSL => RSA

S

_Stud

To understand why I wrote the following code, I wanted to ensure
confidentiality by encrypting some information. I also wanted to
maintain non-reputability by encrypting the string with the senders
private RSA key.

In this configuration, the string is first encrypted with Alice's
private key and then Bob's public key. To decrypt, Bob is the only
one who can decrypt the data, and he knows the data came from Alice
because her public RSA key is also needed.

It doesn't work :-( The error message doesn't make sense to me, so
I'm hoping someone can enlighten me. Maybe I'm not using the
libraries correctly. Thanks for the help.

/-------------------------------------------------------------------------------------/
$stdout = $stderr = File.new("RSA.log","w")

priv_alice= OpenSSL::pKey::RSA.new(1024)
pub_alice = priv_alice.public_key

priv_bob = OpenSSL::pKey::RSA.new(1024)
pub_bob = priv_bob.public_key


string = "Ruby rocks!"

encrypted1 = priv_alice.private_encrypt(string)
encrypted2 = pub_bob.public_encrypt(encrypted1)

decrypted2 = priv_bob.private_decrypt(encrypted2)
decrypted1 = pub_alice.public_decrypt(decrypted2)

puts decrypted1

/-------------------------------------------------------------------------------------/

RSA.rb:13:in `public_encrypt': data too large for key size
(OpenSSL::pKey::RSAError)
from RSA.rb:13
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top