I'm new to RSA encryption and I've been trying to learn how exactly it works using .Net's System.Security.Cryptography
.
public String Encryption(Byte[] Input, RSAParameters PublicKey)
{
RSAC = new RSACryptoServiceProvider();
RSAC.ImportParameters(PublicKey);
Byte[] Encrypt = RSAC.Encrypt(Input, false);
return Convert.ToBase64String(Encrypt);
}
Using the above code, I get a different encrypted string for the same intput, anytime I restart the application. I would like to know if this is a normal behavior and in case it is not, how to prevent it.
For example the program returns the below string for the input "Hello" :
NopDAF5FRu....
When I restart the application the output for the same input will be :
pPPu8x6....
However when I create new objects for my RSA Encryption class, all objects return the same output.
That's totally normal and fine. The data being encrypted is put inside a block that is padded with random values. That's then being encrypted with the public key.
See this SO Q&A for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With