C#中带有PGP的多个接收器(BouncyCastle框架)

本文关键字:接收器 BouncyCastle 框架 PGP | 更新日期: 2023-09-27 18:26:10

我已经能够使用一个公钥加密/解密文件。现在我想用PGP为多个收件人加密文件。我怎样才能做到这一点?

C#中带有PGP的多个接收器(BouncyCastle框架)

我想你正在做这样的事情:

PgpEncryptedDataGenerator encryptedDataGenerator = // ...
encryptedDataGenerator.AddMethod(publicKey);
encryptedDataGenerator.Open(outputStream, buffer);

只需多次使用AddMethod()-方法为其他收件人添加公钥:

PgpEncryptedDataGenerator encryptedDataGenerator = // ...
foreach(PgpPublicKey publicKey in publicKeys){
  encryptedDataGenerator.AddMethod(publicKey);
}
encryptedDataGenerator.Open(outputStream, buffer);

我也处于类似的情况。我自己制作了一个随机会话密钥,它被加密了好几次;每个目标一个。不过,让一切都运转起来有点乱。我不确定OpenPGP是否真的直接支持它(尽管函数名似乎暗示了这一点)