19

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?

14

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 Feb 5 '14 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 Chourasiya Oct 14 '18 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 Oct 15 '18 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 Chourasiya Oct 16 '18 at 2:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.