Search code examples
javabouncycastlepublic-key-encryptionpgp

Bouncy Castle PGP sign and encrypt in one pass?


I'm looking for an implementation of Bouncy Castle PGP 'sign and encrypt'. Ideally in one operation, if that makes any difference.

I've taken the encrypt example and the signing example and tried to turn it into a 'one pass' encrypt and sign operation.

I see this relatively dated implementation Boncode. It seems to show that the two operations are just linked together.

I'm not getting the consumer to decrypt the code. The signature seems to be able to be verified. This is true whether I use the merged operations or separate encrypt then sign.

Is there a better Bouncy Castle PGP implementation?


Solution

  • Latest answer is to use BouncyGPG

    Works as per the test cases. Kotlin

      val encryptionStream = BouncyGPG
                .encryptToStream()
                .withConfig(keyringConfig)
                .withStrongAlgorithms()
                .toRecipient("[email protected]")
                .andSignWith("[email protected]")
                .armorAsciiOutput()
                .andWriteTo(cipherText)
    
        encryptionStream.write(expectedPlaintext)
        encryptionStream.close()
        cipherText.close()