3

我有一个奇怪的问题。我正在使用后面的 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);
}
4

2 回答 2

2

您是根据使用 VS 的调试说的吗?您是否验证了堆栈跟踪或日志以查看是否调用了该方法?

VS 调试器可能会在多线程情况下引导您出错。

于 2011-01-11T19:13:39.797 回答
0

由于 PrivateKey 没有在任何地方使用,也许函数调用被编译器切断了?

于 2011-01-11T18:43:00.047 回答