We have a use case in which we need to be able to perform PGP encryption on a piece of data, natively in Salesforce in Apex code. Does anyone know if there is an open source Apex project or a managed package that offers an Apex API that does PGP encryption?

1 Answer 1


I've never seen one, and I think you will probably have a tough time implementing PGP support natively in Apex. The Crypto API only supports symmetric encryption using AES, and unless I'm forgetting something, PGP needs both symmetric and asymmetric encryption using a couple algorithms. Unless there is some incarnation of PGP you can use that only needs AES encryption, you'd have to implement your own implementation of one of the asymmetric algorithms from scratch, which is going to be difficult-to-impossible using Apex since Apex has basically non-existent support for byte array manipulation.

Your best bet would be to set up a secure web service for doing PGP encryption and call that from Apex. There are numerous good open source PGP implementations in all the major languages.

  • Thanks for the answer, and we have found everything you say to be true. An external web service is probably the way we will proceed.
    – bobbyt
    Commented Feb 5, 2014 at 17:32
  • @bobbyt, I am bit late on this topic but kind of in the same boat. Please let me know how you have implemented it?
    – Sachin
    Commented Oct 14, 2018 at 15:51
  • @SachinChourasiya We ended up implementing the functionality we needed on an AWS Windows machine using some .NET code, and exposed that as an API that we called from our Apex code on the SFDC side. Hope that helps.
    – bobbyt
    Commented Oct 15, 2018 at 16:06
  • @bobbyt, I actually want to encrypt a file in Linux and decrypt in Apex. The file will be posted to Salesforce using webservice as base64 string. I have shared a key to Linux generated by calling generateAESKey(128) function but not able to decrypt file in Salesforce. Please let me know if you can guide?
    – Sachin
    Commented Oct 16, 2018 at 2:44
  • @jkraybill Does salesforce support pgp encryption now? and workarounds? Commented Nov 27, 2022 at 21:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .