Search code examples
bouncycastlepgpopenpgp

Get string output for PGP Encrypt and Sign in one pass using Bouncy Castle


I have the code which can PGP encrypt and sign a file in one pass and save the encrypted data in another file.

The problem is that I have to pass this encrypted data to another API in JSON format. For that I need to convert the encrypted data to a string which can be identified by the API and then later be decrypted.

Is there any way to PGP encrypt and sign a particular string and then get the encrypted response as a string which can later be decrypted.

Apparently reading the file contents to a string and then trying to decrypt the string is not helping.


Solution

  • The solution would be to convert the file contents to a byte array and then base-64 encoding the byte array.