我有一个奇怪的问题。我正在使用c#代码背后的.NET项目。我正在尝试使用公钥/私钥加密/解密文件。自从我开始研究加密以来,这已经发生了几次。关于如何使加密工作的实际问题将在稍后发布。.Net跳过代码
问题是,当我遍历代码时,指针退出例程。它不会崩溃或被try/catch块捕获。
在下面的情况下获取公钥的工作行,但获取私钥的行没有。它只是跳过并返回到调用模块。
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 cspParam 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);
}
很难说,但我怀疑这是一个权限问题(ASP.NET进程没有私钥权限),也许抛出一个异常不是从Exception派生的。 – sdcoder 2011-01-11 18:41:18
你的意思是Windows Forms或ASP.NET? Windows窗体没有隐藏代码。 – 2011-01-11 18:41:49