I am trying to achieve encryption using PGP with bouncy castle version 1.77 and my encrypt method successfully encrypts the input string. This is the code i use to encrypt.
private ByteArrayOutputStream encryptUsingKeyFile(RawMessage rawOut, String key) throws TransformException, PGPException, IOException {
byte[] data = rawOut.getAsBytes();
data = compressFile(data, CompressionAlgorithmTags.ZIP);
PGPPublicKey encKey = readPublicKey(key);
if (encKey == null) {
throw new TransformException("Encrypted Key is NULL");
}
PGPEncryptedDataGenerator encGen = new PGPEncryptedDataGenerator(new JcePGPDataEncryptorBuilder(PGPEncryptedData.CAST5).setWithIntegrityPacket(false).setSecureRandom(new SecureRandom()).setProvider(BouncyCastleProvider.PROVIDER_NAME));
encGen.addMethod(new JcePublicKeyKeyEncryptionMethodGenerator(encKey).setProvider(BouncyCastleProvider.PROVIDER_NAME));
ByteArrayOutputStream out = new ByteArrayOutputStream();
OutputStream cOut = encGen.open(out, data.length);
cOut.write(data);
cOut.close();
return out;
}
Now, users of my encryption method have requested support for the S2K hash algorithms in the PGPEncryptedDataGenerator class.
for ref:
I have searched all along for the usage of those in the encryption, but I’m unable to find code that utilises these S2K Hash algorithms during encryption. AI search has only misled to use of method calls that don’t even exist. Kindly help me on this, since I have stuck on this for days and not able to proceed.
Any help would be highly appreciated.
Here is the documentation for reference