fork download
  1. public class CryptoExample {
  2.  
  3. public static void test(){
  4. CryptoExample.aes256();
  5. }
  6.  
  7. public static void aes256(){
  8. String clearText = 'the quick brown fox jumps over the lazy dog';
  9. //32 byte string. since characters used are ascii, each char is 1 byte.
  10. Blob key = Blob.valueOf('12345678901234567890123456789012');
  11. Blob cipherText = Crypto.encryptWithManagedIV('AES256', key, Blob.valueOf(clearText));
  12. String encodedCipherText = EncodingUtil.base64Encode(cipherText);
  13. System.debug(encodedCipherText);
  14. Blob encodedEncryptedBlob = EncodingUtil.base64Decode(encodedCipherText);
  15. Blob decryptedBlob = Crypto.decryptWithManagedIV('AES256', key, encodedEncryptedBlob);
  16. String decryptedClearText = decryptedBlob.toString();
  17. System.debug(decryptedClearText);
  18. }
  19. }
Success #stdin #stdout #stderr 0s 8848KB
stdin
Standard input is empty
stdout
Object: UndefinedObject error: did not understand #CryptoExample
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
UndefinedObject class(Object)>>doesNotUnderstand: #CryptoExample (SysExcept.st:1448)
UndefinedObject>>executeStatements (prog:1)
stderr
./prog:3: parse error, expected '}'