gpt4 book ai didi

c# - Bouncy CaSTLe PGP解密问题

转载 作者:IT王子 更新时间:2023-10-29 04:45:07 25 4
gpt4 key购买 nike

我有一个使用 Bouncy CaSTLe 进行 PGP 解密的应用程序,它在过去 8 个月左右的时间里运行没有任何问题,而在过去的 2 天里突然出现了一个问题,其中 GetDataStream 方法抛出一个异常:

异常消息:“错误设置非对称密码”。

内部异常消息:“不是 RSA key ”。

private static PgpObjectFactory getClearDataStream(PgpPrivateKey privateKey, PgpPublicKeyEncryptedData publicKeyED)
{
// Exception throws here.
Stream clearStream = publicKeyED.GetDataStream(privateKey);

PgpObjectFactory clearFactory = new PgpObjectFactory(clearStream);
return clearFactory;
}

key 没有过期,它没有过期日期:

enter image description here

我没有对应用程序进行任何更改,也没有触摸按键,所以我不太明白为什么会突然出现问题。有任何想法吗?我还可以使用 Kleopatra 使用我在应用程序中加载的相同 key 手动解密文件。

更新 1 - 我下载了 OpenPGP Library for .NET 的免费试用版,它看起来也使用 BouncyCaSTLe,而且我使用相同的 key 解密文件没有问题。出于某种原因,我使用已经工作了几个月的 BouncyCaSTLe 的解密实现由于某种我还无法确定的原因而停止工作。

更新 2 - 我提取了上周有效的文件,我还下载了 BouncyCaSTLe 的源代码,以便我可以单步执行和调试以查看异常抛出的位置和有效文件和无效文件之间的变量有何不同。在 PgpPublicKeyEncryptedData 类的 GetDataStream 方法的开头抛出异常:

byte[] plain = fetchSymmetricKeyData(privKey);

当我进入此方法时,对于我可以毫无问题地解密的文件,我注意到 keyData.Algorithm 变量设置为“ElGamalEncrypt”,而对于抛出异常的文件,文件 keyData.Algortithm设置为“RsaGeneral”。为什么这些会有所不同?向我发送文件的公司是否更改了他们的加密方法? BouncyCaSTLe 是否不正确支持这种加密方法?

private byte[] fetchSymmetricKeyData(PgpPrivateKey privKey)
{
IBufferedCipher c1 = GetKeyCipher(keyData.Algorithm);

try
{
c1.Init(false, privKey.Key);
}
catch (InvalidKeyException e)
{
throw new PgpException("error setting asymmetric cipher", e);
}

另外,不确定这是否相关,我们 key 的证书类型是 DSA。

enter image description here

更新 3 - 鉴于当前 key ,我一直无法弄清楚如何解决问题。我昨天生成了新 key (类型 DSA),使用新 key 问题已经解决。

更新 4 - 这个问题刚刚再次出现,新 key 在我上次更新中起作用。再一次,PgpPublicKeyEncryptedData 类中的 keyData.Algorithm 现在被“RsaGeneral”而不是“ElGamalEncrypt”看到。为什么 Algorithm 属性会改变?加密文件的人是否更改了某些内容?

最佳答案

这可能很重要(来源:http://www.opensourcejavaphp.net/csharp/itextsharp/PgpPublicKeyEncryptedData.cs.html):

它解释了您的 keyData.Algorithm 的值(value)不同,但我仍然不确定的原因。很可能输入文件就是这种情况。它可能不同(客户端使用不同的 key ?)

private static IBufferedCipher GetKeyCipher(
PublicKeyAlgorithmTag algorithm)
{
try
{
switch (algorithm)
{
case PublicKeyAlgorithmTag.RsaEncrypt:
case PublicKeyAlgorithmTag.RsaGeneral:
return CipherUtilities.GetCipher("RSA//PKCS1Padding");
case PublicKeyAlgorithmTag.ElGamalEncrypt:
case PublicKeyAlgorithmTag.ElGamalGeneral:
return CipherUtilities.GetCipher("ElGamal/ECB/PKCS1Padding");
default:
throw new PgpException("unknown asymmetric algorithm: " + algorithm);
}
}
catch (PgpException e)
{
throw e;
}
catch (Exception e)
{
throw new PgpException("Exception creating cipher", e);
}
}

关于c# - Bouncy CaSTLe PGP解密问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11106918/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com