Encrypt Data using Public Key in Java

Hi. I am trying to consume my Passbolt API from a Java project. And I am not familiar with encryption algorithms. I am following the guide “Using Postman to get Familiar with Passbolt API” refered in How to complete initial API auth steps using Postman?. I followed it in Postman. Now, I am trying to do it in Java.

I could save the server’s public key returned by the API in a PGPPublicKey object. I use BouncyCastle library. This is the fragment code:

InputStream in = new ByteArrayInputStream(serverPublicKeyContent.getBytes());
in = PGPUtil.getDecoderStream(in);

JcaPGPPublicKeyRingCollection pgpPub = new JcaPGPPublicKeyRingCollection(in);

Iterator<PGPPublicKeyRing> rIt = pgpPub.getKeyRings();

while (serverPublicKey == null && rIt.hasNext()) {
	PGPPublicKeyRing kRing = rIt.next();
	Iterator<PGPPublicKey> kIt = kRing.getPublicKeys();
	while (serverPublicKey == null && kIt.hasNext()) {
		PGPPublicKey k = kIt.next();
		if (k.isEncryptionKey()) {
			serverPublicKey = k;

Now, I am trying to send encrypted data to the server using this server’s public key. However, I don’t know how do it in Java.

An example of data to encrypt is:


Could somebody help me, please? Thank you very much in advance.

@idsev89 The mobile app for Android might be helpful https://github.com/passbolt/mobile-passbolt-android/tree/master/services/passboltapi/src/main/java/com/passbolt/mobile/android/passboltapi