3

I have already been able to manage to encrypt/decrypt files using one Public Key. Now I'd like to encrypt files with PGP for multiple receipients. How can I achieve this?

stromflut
  • 186
  • 1
  • 9

2 Answers2

1

I assume you are doing something like this:

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

Just add the public keys for the other recipients using the AddMethod()-method multiple times:

PgpEncryptedDataGenerator encryptedDataGenerator = // ...
foreach(PgpPublicKey publicKey in publicKeys){
  encryptedDataGenerator.AddMethod(publicKey);
}
encryptedDataGenerator.Open(outputStream, buffer);
Rasmus Faber
  • 48,631
  • 24
  • 141
  • 189
  • 2
    This seems to work for the encryption, but there is another problem in decrypting the encrypted files afterwards. If I decrypt the file with the secret Key of the First-added PublicKey, I get the Original File back. But if I use the secret key of the secondly-Added Public Key, I get a "exception decrypting secret key"-Error. It's allways the second key which generates some Problems - even if I switch the Position of these two Keys... – stromflut Mar 05 '12 at 14:49
0

I'm in a similar situation. I've resorted to making a random session key myself, which is encrypted several times; one for each target. It's a little messy to get everything working though. I'm not sure if it's really supported by OpenPGP straight out of the box (even though the function names seem to suggest it)