fork download
  1. // Generate an AES key for the purpose of this sample.
  2. // Normally this key should be stored in a protected //custom setting
  3. // or an encrypted field on a custom object
  4. Blob cryptoKey = Crypto.generateAesKey(256);
  5.  
  6. // Generate the data to be encrypted.
  7. Blob data = Blob.valueOf('Test data to encrypted');
  8. // Encrypt the data and have Salesforce.com generate the //initialization vector
  9. Blob encryptedData = Crypto.encryptWithManagedIV('AES256', cryptoKey, data);
  10. // Decrypt the data - the first 16 bytes contain the //initialization vector
  11. Blob decryptedData = Crypto.decryptWithManagedIV('AES256', cryptoKey, encryptedData);
  12.  
  13. // Decode the decrypted data for subsequent use
  14. String decryptedDataString = decryptedData.toString();
Success #stdin #stdout #stderr 0.01s 7716KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
./prog:1: expected expression