-1

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.

Artjom B.
  • 61,146
  • 24
  • 125
  • 222

2 Answers2

2

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)
Peter Dettman
  • 3,867
  • 20
  • 34
0

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));
Gildos
  • 41
  • 2