We want to encrypt data generated in a Ruby on Rails app to be encrypted, passed to Salesforce, and then be decrypted in Apex code.
This seems like a clear case for using
decrypt(algorithmName, privateKey, initializationVector, cipherText)
Decrypts the Blob cipherText using the specified algorithm, private key, and initialization vector. Use this method to decrypt blobs encrypted using a third party application or the encrypt method.
Blob exampleIv = Blob.valueOf('Example of IV123'); Blob key = Crypto.generateAesKey(128); Blob data = Blob.valueOf('Data to be encrypted'); Blob encrypted = Crypto.encrypt('AES128', key, exampleIv, data); Blob decrypted = Crypto.decrypt('AES128', key, exampleIv, encrypted); String decryptedString = decrypted.toString(); System.assertEquals('Data to be encrypted', decryptedString);
But I can't find anywhere how to do this using something other than a
Blob generated within Apex. As far as I can tell, I need to get this key out of Salesforce to use it elsewhere, but I can't figure out how.
I also found examples on this page, https://developer.salesforce.com/page/Apex_Crypto_Class , but it also doesn't tell me how to get my key between my external app and my Salesforce org. It just says to store it in a custom setting or custom object.