Wednesday, 30 April 2014

Encrypt and Decrypt in salesforce using apex and vf page

<apex:page standardController="EnCrypt_Decrypt__c" extensions="EncryptExtensioncls">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection >
                <apex:inputField value="{!encrypt.Name}"/>
                <apex:commandButton value="Save" action="{!Save}"/>
                <apex:commandButton value="Update" action="{!test}"/>


public class EncryptExtensioncls{
    public EnCrypt_Decrypt__c encrypt{get;set;}
    //Blob cryptoKey;
    Blob cryptoKey = Blob.valueOf('51266ysaj6671678');
    public Id recordId{get;set;}
    public EncryptExtensioncls(ApexPages.StandardController controller) {
        //cryptoKey = Crypto.generateAesKey(256);
        recordId = Apexpages.CurrentPage().getParameters().get('id');
        if(recordId !=null){
            encrypt = [SELECT id,Name From EnCrypt_Decrypt__c
                    WHERE id=:recordId];
            encrypt = new EnCrypt_Decrypt__c();
    public PageReference Save(){
         Blob data = Blob.valueOf(encrypt.Name);
         Blob encryptedData = Crypto.encryptWithManagedIV('AES128', cryptoKey , data );
         String b64Data = EncodingUtil.base64Encode(encryptedData);
         = b64Data ;
         insert encrypt;
         return null;
    public PageReference test(){
         //Blob cryptoKey = Crypto.generateAesKey(256);
         //Blob data = Blob.valueOf(encrypt.Name);
         Blob data = EncodingUtil.base64Decode(encrypt.Name);
         Blob decryptedData = Crypto.decryptWithManagedIV('AES128', cryptoKey , data);
         String dryptData = decryptedData.toString();
         System.debug('Printing dryptData '+dryptData);
         = dryptData;
         update encrypt;
         return null;

1 comment:

customize omni channel logic to distribute cases based on Case Creation Date

Omni Channel queues distributes cases, based on Date/Time the case is assigned to the queue. we can customize this logic to look for some ...