Reputation: 18868
I am using BouncyCastle package for OpenPGP encryption. Everything is smooth except one part. When I write the encrypted text to file, it's appending the below message
-----BEGIN PGP MESSAGE-----
Version: BCPG v1.47
//encrypted text here
-----END PGP MESSAGE-----
But i don't want the signature part in the file. Here's the code I am using for encryption
public void encryptFile(OutputStream out, String fileName, PGPPublicKey encKey, boolean armor, boolean withIntegrityCheck) throws IOException, NoSuchProviderException, PGPException {
//armor = true; integrityCheck = true
Security.addProvider(new BouncyCastleProvider());
if (armor) {
out = new ArmoredOutputStream(out);
}
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
PGPCompressedDataGenerator comData = new PGPCompressedDataGenerator(PGPCompressedData.ZIP);
PGPUtil.writeFileToLiteralData(comData.open(bOut), PGPLiteralData.BINARY, new File(fileName));
comData.close();
BcPGPDataEncryptorBuilder dataEncryptor = new BcPGPDataEncryptorBuilder(PGPEncryptedData.AES_256);
dataEncryptor.setWithIntegrityPacket(withIntegrityCheck);
dataEncryptor.setSecureRandom(new SecureRandom());
PGPEncryptedDataGenerator encryptedDataGenerator = new PGPEncryptedDataGenerator(dataEncryptor);
encryptedDataGenerator.addMethod(new BcPublicKeyKeyEncryptionMethodGenerator(encKey));
byte[] bytes = bOut.toByteArray();
OutputStream cOut = encryptedDataGenerator.open(out, bytes.length);
cOut.write(bytes);
cOut.close();
out.close();
}
Upvotes: 0
Views: 654
Reputation: 46080
This is not the signature but an envelope for armored data. Turn off armoring and you'll get binary encrypted data. If you remove the envelope and keep armoring, conformant decrypting OpenPGP tools won't know what to do with this - they wouldn't be able to distinguish armored from non-armored data.
Upvotes: 3