String cryptoSalt='249D5EC76175B12A';
Blob cryptoKey=Blob.valueof('J@NcRfUjXn2r5u8x/A?D(G-KaPdSgVkY');
Blob cryptoIv =Blob.valueof('4t6w9z$C&F)J@NcR');
Blob data = Blob.valueOf('youremail@gmail.com'+cryptoSalt);
Blob encryptedData = Crypto.encrypt('AES256', cryptoKey, cryptoIv, data);
String encodeDataHex = EncodingUtil.convertToHex(encryptedData);
System.debug('>>> encodeDataHex >>> ' + encodeDataHex);
//92939c472350e797aca42206a1b1d90f3b33bd1dbbac23af5fba40866515ef43e11e35edd354d341253bf89eb4094f2c
String encodeData = EncodingUtil.base64Encode(encryptedData);
System.debug('>>> encodeData >>> ' + encodeData);
//kpOcRyNQ55espCIGobHZDzszvR27rCOvX7pAhmUV70PhHjXt01TTQSU7+J60CU8s
// Decrypt the data - the first 16 bytes contain the initialization vector
Blob decodeData = EncodingUtil.base64Decode(encodeData);
Blob decryptedData = Crypto.decrypt('AES256', cryptoKey, cryptoIv, decodeData);
// Decode the decrypted data for subsequent use
String decryptedDataString = decryptedData.toString();
System.debug('>>> ' + decryptedDataString);
//youremail@gmail.com249D5EC76175B12A
Like this:
Like Loading...
Related
Published by Thys Michels
Cloud Architect - Salesforce and everything related
View all posts by Thys Michels