简体   繁体   中英

Is there a way to encrypt/decrypt using Bouncy Castle without using compression

I'm looking for a way to encrypt/decrypt files/byte arrays without calling compression of input. To be more precises don't want to use something like

ByteArrayOutputStream bOut = new ByteArrayOutputStream();
PGPCompressedDataGenerator comData = new PGPCompressedDataGenerator(algorithm);
PGPUtil.writeFileToLiteralData(comData.open(bOut), PGPLiteralData.BINARY, new File(fileName));

Any reference, code sample is more than welecome, Thanks.

You avoid adding compression in PGP by simply not adding the code that does it. For your question to be sensible, I would expect you to post an example that has signing/encryption + compression, then we could suggest how to remove the compression bits.

Actually the simplest way for you might be to just set "uncompressed" like this:

new PGPCompressedDataGenerator(algorithm, CompressionAlgorithmTags.UNCOMPRESSED)

The simpler way to do that is to chose CompressionAlgorithmTags.UNCOMPRESSED . If you do that, when you decrypt the file, from the object JcaPGPObjectFactory you still receive a PGPCompressedData (to be decompressed) instead of a PGPLiteralData .

To receive directly a PGPLiteralData , you could avoid at all the compression. Taking your code as an example, you could write:

ByteArrayOutputStream bOut = new ByteArrayOutputStream();
PGPUtil.writeFileToLiteralData(bOut, PGPLiteralData.BINARY, new File(fileName));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM