【发布时间】:2017-03-07 05:27:54
【问题描述】:
我对 BouncyCastle 有一点奇怪的问题。
发生的事情是我正在使用公钥加密文本文件,然后将其传输给第三方。当他们尝试自动解密文件时(使用 Globalscape - 不确定版本),该过程失败,要求输入密码来解锁密钥。
如果我执行相同的过程,但使用 GPG4Win 使用相同的密钥加密文件,他们不会遇到相同的问题。
这是进行加密的代码:
private static bool EncryptFile(Stream outputStream, string fileName, PgpPublicKey encKey, bool withIntegrityCheck)
{
try
{
var bytes = PgpUtils.CompressFile(fileName, CompressionAlgorithmTag.Uncompressed);
// encrypt using AES-256
var encryptedDataGenerator = new PgpEncryptedDataGenerator(SymmetricKeyAlgorithmTag.Aes256, withIntegrityCheck, new SecureRandom());
encryptedDataGenerator.AddMethod(encKey);
using (var cOutStream = encryptedDataGenerator.Open(outputStream, bytes.Length))
{
cOutStream.Write(bytes, 0, bytes.Length);
}
return true;
}
catch (Exception e)
{
Trace.TraceError($"Exception in EncryptFile: {e}");
return false;
}
}
我承认我在这里有点迷失了。谁能指出我错过了什么?还是我应该要求第三方进一步挖掘?
干杯
【问题讨论】:
标签: c# bouncycastle public-key-encryption