Created
January 26, 2014 10:20
-
-
Save msrivastav13/8630895 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generate an AES key for the purpose of this sample. | |
// Normally this key should be stored in a protected custom setting | |
// or an encrypted field on a custom object | |
Blob cryptoKey = Crypto.generateAesKey(256); | |
// Generate the data to be encrypted. | |
Blob data = Blob.valueOf('Test data to encrypted'); | |
// Encrypt the data and have Salesforce.com generate the initialization vector | |
Blob encryptedData = Crypto.encryptWithManagedIV('AES256', cryptoKey, data); | |
// Decrypt the data - the first 16 bytes contain the initialization vector | |
Blob decryptedData = Crypto.decryptWithManagedIV('AES256', cryptoKey, encryptedData); | |
// Decode the decrypted data for subsequent use | |
String decryptedDataString = decryptedData.toString(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment