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
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.– bobbytFeb 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?– SachinOct 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.– bobbytOct 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?– SachinOct 16, 2018 at 2:44
-
@jkraybill Does salesforce support pgp encryption now? and workarounds? Nov 27, 2022 at 21:18