function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
karimulla testingkarimulla testing 

encrption and decrption in salesforce

Hi All,

I have tried to pass user name and password  site url, is look like the below.

This is working fine ,
but i want to encrypt the username and password while passing in url for security reasons and also want to decript username and password in salesforce side

In my site URL i am using the standard page, is 'login'. is this possible to decrypt the username and password from 'login' page

Over all my requirement is, we have one link. Link contains the above url. User can able to login to  by clicking the link without enter the credentials (Custom SSO). In this we want to make the user name and password in the form of encrypt or hide.

Please give me any solutions or work arounds for this
NagendraNagendra (Salesforce Developers) 
Hi Karimulla,

Sorry for this issue you are encountering.

May I suggest you please check with below link from the forums community exactly with a similar issue and a suggested workaround which should help you with the above requirement. Hope this will help you.

Kindly mark this as solved if it's resolved.

karimulla testingkarimulla testing
public class EncryptExtensioncls{
    public Employee__c encrypt{get;set;}
   public Employee__c query{get;set;}
  //Blob cryptoKey;
     Blob cryptoKey = Blob.valueOf('12345678901234561234567890123456');  //it 32bytes
        public Id recordId{get;set;}
    public EncryptExtensioncls(ApexPages.StandardController controller) {
          //cryptoKey = Crypto.generateAesKey(256);
         // recordId = Apexpages.CurrentPage().getParameters().get('name');
      recordId = ApexPages.CurrentPage().getParameters().get('id');
          if(recordId !=null){
               encrypt = [SELECT id,Name,password__c From Employee__c 
                                                                       WHERE id=:recordId];
            encrypt = new Employee__c();
        PageReference pageRef = new PageReference('{!query.password__c}&un={!}');

        public PageReference Encrypt(){
         Blob data = Blob.valueOf(encrypt.Name);
         Blob encryptedData = Crypto.encryptWithManagedIV('AES256', cryptoKey , data );
         String b64Data = EncodingUtil.base64Encode(encryptedData); = b64Data ;
          Blob data2 = Blob.valueOf(encrypt.Password__c);
         Blob encryptedData2 = Crypto.encryptWithManagedIV('AES256', cryptoKey , data2 );
         String b64Data2 = EncodingUtil.base64Encode(encryptedData2);
         encrypt.Password__c = b64Data2 ;
         insert encrypt;
       //  PageReference pg = new PageReference (' ');
      //  PageReference pg = new PageReference ('/apex/EncryptExtensioncls?pw={!encrypt.Password__c}&un={!}');        
      /*   PageReference pg = new PageReference ('/apex/EnD?pw={!b64Data2}&un={!b64Data}');            
         return pg; */
             return null;
    public PageReference Decrypt(){
         //Blob cryptoKey = Crypto.generateAesKey(256);
         //Blob data = Blob.valueOf(encrypt.Name);
         Blob data = EncodingUtil.base64Decode(encrypt.Name);
         Blob decryptedData = Crypto.decryptWithManagedIV('AES256', cryptoKey , data);
         String dryptData = decryptedData.toString();
         System.debug('Printing dryptData '+dryptData);
          = dryptData;
         Blob data2 = EncodingUtil.base64Decode(encrypt.Password__c);
         Blob decryptedData2 = Crypto.decryptWithManagedIV('AES256', cryptoKey , data2);
         String dryptData2 = decryptedData2.toString();
         System.debug('Printing dryptData '+dryptData2);
         encrypt.Password__c = dryptData2;
         update encrypt;
      /*  PageReference pg = new PageReference ('/apex/EnD?pw={!b64Data2}&un={!b64Data}');            
         return pg; */
        return null; 

                //public soql1(){
       //  soql =[select id, name FROM Employee__c where industry ='checkmark' LIMIT 1];
                   // } 


<apex:page standardController="Employee__c" extensions="EncryptExtensioncls">

    <apex:form >   
         <apex:outputLabel >User Name</apex:outputLabel>
             <apex:inputField value="{!encrypt.Name}" html-placeholder="Username" /> 
              <apex:outputLabel >Password</apex:outputLabel>
              <apex:inputText value="{!encrypt.Password__c}" html-placeholder="Password"/>
              <apex:commandButton value="Encrypt" action="{!Encrypt}"/> 
               <apex:commandButton value="Decrypt" action="{!Decrypt}"/>
     <apex:pageBlock >
            <apex:pageBlockSection >
                    <apex:outputField value="{!encrypt.Name}"/>
                    <apex:outputField value="{!encrypt.Password__c}"/>