Public/Private key problems

Lately, I’ve been working on a project that has some pretty heavy duty encryption requirements.  This stuff is very cool, but somewhat mysterious.  I have run into these two errors and couldn’t really find a good description of what they are or more importantly, how to fix them.

Input too large for rsa cipher


Unknown block type

The problem is that without the code changing at all these two errors pop up all the time but very randomly.

These errors stem from the fact that we’re trying to decrypt some data with a private key that does not match the public key that was used to encrypt it.

Let’s take a quick look at how public key/private key encryption works.

First of all, I have a public key and a private key.  I share my public key with anyone who wants it.  The person I’m sharing data with also has a public key and a private key.  They give me their public key but not their private key.

When I want to send them data, I will use their public key to encrypt the data and then send them the encrypted data.  They will use their private key to decrypt it.  Likewise, when they want to send me data, they’ll use my public key to encrypt it and then I’ll use my private key to decrypt it.

The errors above were coming from the fact that the public key they were using didn’t match my private key.  Basically, I was trying to decrypt data with the wrong “password”.

Leave a Reply

Scroll To Top