Reputation: 63
I'm reading private and public keys from XML String in my C# program. Encryption(with private key) works fine. But when it comes to Decryption(with public Key) it throws following error.
System.Security.Cryptography.Cryptographic Exception {"Key does not exist.\r\n"}
var rsa = new RSACryptoServiceProvider();
rsa.FromXmlString(_privateKey);
rsa.FromXmlString(_publicKey);
byte[] messagee = Encoding.UTF8.GetBytes("win win win");
byte[] encrypted = rsa.Encrypt(messagee, false);
string encString = Encoding.UTF8.GetString(encrypted);
byte[] decrypt = rsa.Decrypt(encrypted,false);
string decString = Encoding.UTF8.GetString(decrypt);
Why is that? I searched every where, but couldn't find any solution.
Thanks in advance.
Upvotes: 1
Views: 6300