neuhalje / bouncy-gpg

Make using Bouncy Castle with OpenPGP fun again!
https://neuhalje.github.io/bouncy-gpg/
Other
205 stars 58 forks source link

Generate signature for CANONICAL_TEXT_DOCUMENT #60

Open bjansen opened 3 years ago

bjansen commented 3 years ago

I have a use-case where I need to sign and encrypt a canonical text document rather than a binary document (see https://tools.ietf.org/html/rfc4880#section-5.2.1). This should replace \n with \r\n and set a particular flag, from what I understand.

It looks like the best way is to modify name.neuhalfen.projects.crypto.bouncycastle.openpgp.encrypting.PGPEncryptingStream#setup to make this statement configurable:

signatureGenerator.init(PGPSignature.BINARY_DOCUMENT, pgpPrivKey);

The PGPSignature.BINARY_DOCUMENT could be something that can be changed in BuildEncryptionOutputStreamAPI?

BouncyGPG
    .encryptToStream()
...
    .andSignWith(uid, PGPSignature.CANONICAL_TEXT_DOCUMENT)
    .binaryOutput()
    .andWriteTo(...)
bjansen commented 3 years ago

@neuhalje I can provide a PR if you tell me if you'd rather have an overload for andSignWith(), or a new method like withSignatureType()