I have an integration with another system which I should use the AES Algorithm.The Encryption is made in SF side - and sent in the header of an HTTP request. This made to recognize SF in internal services which won't whitelist 1M IPs. They use ECB Algorithm but I understood that SF does not support this method.
I have two methods that I can use to encrypt:
- with initialization vector (IV):
Blob cryptoKey = Blob.valueOf('1234567891234567');
String binaryString = EncodingUtil.base64Encode(cryptoKey);
System.debug(EncodingUtil.base64Encode(cryptoKey));
Blob data = Blob.valueOf('some Text to encrypt');
Blob MY_IV = Blob.valueOf('0987654321098765');
Blob encrypted = Crypto.encrypt('AES128', cryptoKey,MY_IV, data);
- with managed IV:
Blob cryptoKey = Blob.valueOf('1234567891234567');
Blob data = Blob.valueOf('some Text to encryped');
Blob encrypted = Crypto.encryptWithManagedIV('AES128', cryptoKey, data);
My questions are:
If I am using the second method with the managed IV, I get the plaintext with kind of gibberish at the beginning of the text when decrypted. Why it happens and how can I solve it?
is there another algorithm that can serve my needs instead of AES?
Is there any link or example of how can I make my own encryption?
Is there any workaround to make the ECB in apex?
many thanks.