.Net Skipping Code
I am having a strange problem. I am working on a .net windows project using c# code behind. I am trying to encrypt/decrypt files using public/private keys. This has happened to me a few times since I start working on encryption. The actual issue of how to get encryption to work will be another posting later.
The problem is that while stepping through my code the pointer exits the routine. It does not crash or get caught in the try/catch block.
In the case below the line to get the public key works, but the line to get the private key does not. it just skips out and returns to the calling module.
string publicKey; // gets the public key
string privateKey; // gets the private key
try
{
CspParameters cspParam = new CspParameters();
cspParam.Flags = CspProviderFlags.UseMachineKeyStore;
System.Security.Cryptography.RSACryptoServiceProvider RSA =
new System.Security.Cryptography.RSACryptoServiceProvider(cspParam);
// The key information
//from the cspPara开发者_运维问答m object above can be saved via
//select the;
publicKey = RSA.ToXmlString(false); // gets the public key
privateKey = RSA.ToXmlString(true); // gets the private key
string x = publicKey;
}
catch (Exception ex)
{
clsGetMessage.DisplayError(ex);
}
Did you say this based on the debugging using VS? did you verify the stack trace or logs to see if the method is called?
VS debuggers may guide you wrong in multi threaded cases.
Since PrivateKey is not used anywhere, maybe function call is cut away by compiler?
精彩评论