Advanced Encryption Standard(AES) using Salesforce Apex

Advanced Encryption Standard(AES) using Salesforce Apex

We can use Crypto.encryptWithManagedIV() and Crypto.decryptWithManagedIV() with at least 16 bytes key for Advanced Encryption Standard(AES) using Salesforce Apex.

Sample Code:

/* Encryption */
Blob key = Blob.valueOf(
	'1234567890=abcde'
);
Blob blobData = Blob.valueOf(
	'Sample Data to be encrypted'
);
Blob encryptedBlob = Crypto.encryptWithManagedIV(
	'AES128', 
	key, 
	blobData
);
/* Decryption */
Blob decryptedBlob = Crypto.decryptWithManagedIV(
	'AES128',
	 key, 
	 encryptedBlob
);
String decryptedString = decryptedBlob.toString();
System.debug(
	decryptedString
);

Leave a Reply