I encrypted the text using RSACryptoServiceProvider. I exported the public and private key. Obviously, I just want to open the public key inside the decoder application, so I wrote the code as follows:
private const string PublicKey = "<RSAKeyValue><Modulus>sIzQmj4vqK0QPd7RXKigD7Oi4GKPwvIPoiUyiKJMGP0qcbUkRPioe2psE/d3c1a2NY9oj4Da2y1qetjvKKFad2QAhXuql/gPIb1WmI+f6q555GClvHWEjrJrD/ho7SLoHbWd6oY6fY609N28lWJUYO97RLVaeg2jfNAUSu5bGC8=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>"; private string Decrypt() { byte[] encryptedKeyAsBytes = Convert.FromBase64String(_encryptedKey); RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(); rsa.FromXmlString(PublicKey);
But the exception is thrown in the line "byte [] plainBytes = rsa.Decrypt (encryptedKeyAsBytes, false);" and says, "The key does not exist." However, if I expose the entire private and public key, it will work successfully. So, how can I decrypt data using only public key information?
source share