I am trying to implement RSA Encryption into my C# program.
Here is my code :
using System;
using System.Security.Cryptography;
string dataToEncrypt = "Data to Encrypt here";
string modulus= "Public Key here";
string exponent= "Public Key Kxpiry here";
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
RSAParameters RSAKeyInfo = new RSAParameters();
RSAKeyInfo.Modulus = Encoding.UTF8.GetBytes(modulus);
RSAKeyInfo.D = Encoding.UTF8.GetBytes(dataToEncrypt);
RSAKeyInfo.Exponent = Encoding.UTF8.GetBytes(exponent);
RSA.ImportParameters(RSAKeyInfo);
I receive this error code :
System.Security.Cryptography.CryptographicException: 'Bad Data.'
This line is giving the error : RSA.ImportParameters(RSAKeyInfo);
Other information :
- Visual Studio 2019
- Windows Forms App (.NET Framework)
- Operating System : Windows 10 Professional
What am I missing/doing wrong?