mattosaurus / PgpCore

.NET Core class library for using PGP
MIT License
245 stars 98 forks source link

Selecting key in keyring for encryption #125

Closed j355y closed 3 years ago

j355y commented 3 years ago

Hello, I'm having a hard time using a public keyring.

I'm loading it from a file, and I'm able to list the keys in it :

using (FileStream stream = File.Open("/app/crypt/public_keyring2.gpg", FileMode.Open))
    {
         PgpPublicKeyRing _keyRing = new PgpPublicKeyRing(stream);                
        var keys = _keyRing.GetPublicKeys();

         foreach (PgpPublicKey key in keys)
         {
               Console.WriteLine(string.Format("{0:X}", key.KeyId));             
         }
    }

But how can I use a specific key from the keyring to encrypt a file?

I'm trying to do like with gpg.exe when specifying a recipient. I want to use one of many keys in my keyring.

Of course, I know which keyID I want to use, but I cannot figure out how to use a specific key for encryption.

Thank you

mattosaurus commented 3 years ago

Hi,

Unfortunatly I haven't had a chance to implement loading keys from a keyring yet. For the time being I suggest exporting the keys you need from the bundle using another process (gpg.exe maybe) and then using PgpCore with these keys.

I'll look at adding this in when I can but feel free to submit a PR if you'd like, I think this will just require some changes to the EncryptionKeys object.

j355y commented 3 years ago

Thank you!