I am developing a .net standard(.net standard 2.0) library.
I have a public key, which is created in server side and I have received it by an api call.
Now I have a string to be encrypted using RSA algorithm . Also, I have to use this public key while encrypting the string which I have.
I went through various samples, but nothing helped.
Tried this one RSA public key encryption in C#
But got error "Operation is not supported on this platform." .
Tried this one, but couldn't find a way to use public key which I have recieved from server.
Here is the latest code which I have tried . I am not sure how and where to use my public key string .
static public byte[] Encryption(byte[] Data, RSAParameters RSAKey, bool DoOAEPPadding)
{
try
{
byte[] encryptedData;
using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider())
{
RSA.ImportParameters(RSAKey);
encryptedData = RSA.Encrypt(Data, DoOAEPPadding);
}
return encryptedData;
}
catch (CryptographicException e)
{
Console.WriteLine(e.Message);
return null;
}
}
static public byte[] Decryption(byte[] Data, RSAParameters RSAKey, bool DoOAEPPadding)
{
try
{
byte[] decryptedData;
using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider())
{
RSA.ImportParameters(RSAKey);
decryptedData = RSA.Decrypt(Data, DoOAEPPadding);
}
return decryptedData;
}
catch (CryptographicException e)
{
Console.WriteLine(e.ToString());
return null;
}
}
Here i can see RSAKey
but it doesn't accept string input.
Can anyone guide me with some samples, through which i can encrypt and decrypt a simple text, with the public which i have.
Thanks,
Noorul.
question from:
https://stackoverflow.com/questions/65829473/how-to-use-public-key-in-rsa-encryption-c-sharp-net-standard-2-0 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…