I have a strange problem. I am working on a .net windows project using C # code. I am trying to encrypt / decrypt files using public / private keys. This has happened to me several times since I started working on encryption. The actual question of how to get encryption to work will be another post later.
The problem is that when my code runs, the pointer exits the subroutine. It does not crash and does not fall into the try / catch block.
In the example below, the row to get the public key works, but the row to get the private key does not work. it just skips and returns to the calling module.
string publicKey;
string privateKey;
try
{
CspParameters cspParam = new CspParameters();
cspParam.Flags = CspProviderFlags.UseMachineKeyStore;
System.Security.Cryptography.RSACryptoServiceProvider RSA =
new System.Security.Cryptography.RSACryptoServiceProvider(cspParam);
publicKey = RSA.ToXmlString(false);
privateKey = RSA.ToXmlString(true);
string x = publicKey;
}
catch (Exception ex)
{
clsGetMessage.DisplayError(ex);
}
source
share