justinludwig / jpgpj

Java Pretty Good Privacy Jig
MIT License
75 stars 20 forks source link

The Decyptor example in the README.md has the keys in the wrong order #5

Closed ghost closed 6 years ago

ghost commented 7 years ago

I've tried decrypting with the order of the keys in the Decryptor constructor being identical to the README.md example and I got an error (public key not found). After switching the order of the keys it works fine.

Also, thank you very much for this extremely simple-to-use and actually working implementation of the PGP flow! You should add a bitcoin/monero address for donations.

justinludwig commented 6 years ago

Thanks for reporting this bug! Sorry for taking so long to respond -- I'm not 100% sure this is the same issue you experienced, but I was able to reproduce it when using the same key for encryption and signing, and specifying the public key and private key separately to the Decryptor constructor, with the public key first, like this:

new Decryptor(
    new Key(new File("path/to/my/keys/alice-pub.gpg")),
    new Key(new File("path/to/my/keys/alice-sec.gpg"), "password123")
).decrypt(
    new File("path/to/ciphertext.txt.gpg"),
    new File("path/back-to/plaintext.txt")
);

This results in a org.c02e.jpgpj.DecryptionException being thrown with a no suitable decryption key found message. I will fix this bug so that the Decryptor decrypts and verifies the ciphertext as expected.

justinludwig commented 6 years ago

I fixed it so that if you specify the public key and secret key separately for the same public-key pair on the same key ring, decryption will work no matter in what order you specified the keys.