Reputation: 7352
I need an asymmetric encryption algorith which always encrypts the data with same result for same data. When I use RSACryptoServiceProvider
it is always giving me different encrypted data for same input.
byte[] encrypted1, encrypted2;
using ( var RSA1 = new RSACryptoServiceProvider() )
{
encrypted1 = RSA1.Encrypt(data, false);
encrypted2 = RSA1.Encrypt(data, false);
}
Here encrypted1
and encrypted2
are different.
I heard this is caused by the random padding ability of new RSA implementation. But it happens even if I set padding to the false. So;
Upvotes: 1
Views: 1237
Reputation: 93978
The boolean you are referring to is not meant to switch the padding on or off. It uses OAEP padding or PKCS#1 v1.5 padding (it should never have been a boolean in the first place, it should have been an enum value). Both padding mechanisms deploy (partially) randomized padding. As long as your random source is indeed random, the output won't be deterministic.
You can of course create your own padding, e.g. using the BlindedRSAEngine
of Bouncy Castle, but if you remove the random padding, you invalidate the security of RSA. Only do this if you fully understand the implications, as for instance indicated here.
In other words: don't go there.
Upvotes: 1