【发布时间】:2011-06-07 08:53:54
【问题描述】:
我遇到了一个奇怪的问题。我正在使用后面的 c# 代码开发一个 .net windows 项目。我正在尝试使用公钥/私钥加密/解密文件。自从我开始从事加密工作以来,这种情况已经发生过几次。如何让加密工作的实际问题将在稍后发布。
问题在于,在单步执行我的代码时,指针退出了例程。它不会崩溃或被 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 派生的异常。
-
您是指 Windows 窗体还是 ASP.NET? Windows 窗体没有代码隐藏。
-
Visual Studio 中的窗体。
-
关于蒂亚戈的评论。我去了我的个人资料,但我没有看到你在说什么。请更具体。
标签: c# windows visual-studio public-key-encryption