【发布时间】:2015-09-04 19:49:56
【问题描述】:
我正在努力添加对使用 GPG 和对称加密加密的文件进行解密的功能。
但是,每当它尝试获取私钥数据时,此异常就会不断受到攻击:
无法将“Org.BouncyCastle.Bcpg.OpenPgp.PgpPbeEncryptedData”类型的对象转换为“Org.BouncyCastle.Bcpg.OpenPgp.PgpPublicKeyEncryptedData”类型。
我看到的每一个地方都是你这样做的:
Stream inputStream = IoHelper.GetStream(inputData);
PgpObjectFactory pgpFactory = new PgpObjectFactory(PgpUtilities.GetDecoderStream(inputStream));
PgpObject pgp = null;
if (pgpFactory != null)
{
pgp = pgpFactory.NextPgpObject();
}
PgpEncryptedDataList encryptedData = null;
if (pgp is PgpEncryptedDataList)
{
encryptedData = (PgpEncryptedDataList)pgp;
}
else
{
encryptedData = (PgpEncryptedDataList)pgpFactory.NextPgpObject();
}
Stream privateKeyStream = File.OpenRead(PrivateKeyOnlyPath);
// find secret key
PgpSecretKeyRingBundle pgpKeyRing = new PgpSecretKeyRingBundle(PgpUtilities.GetDecoderStream(privateKeyStream));
PgpPrivateKey privateKey = null;
foreach (PgpPublicKeyEncryptedData pked in encryptedData.GetEncryptedDataObjects())
{
privateKey = FindSecretKey(pgpKeyRing, pked.KeyId, Password.ToCharArray());
if (privateKey != null)
{
//pubKeyData = pked;
break;
}
}
我引用here的代码
我不知道为什么它不起作用,也不知道下一步该去哪里。
【问题讨论】:
标签: c# bouncycastle encryption-symmetric openpgp