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.
https://www.salesforce.com/login.jsp?pw=12345&un=sourcetesting@gmail.com



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.

Thanks,
Nagendra
 
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];
        }
        else{
        
            encrypt = new Employee__c();
        }
    }
    
    
    
   
    
     
        PageReference pageRef = new PageReference('https://www.salesforce.com/login.jsp?pw={!query.password__c}&un={!query.name}');

    
    
    
   
        public PageReference Encrypt(){
         
         Blob data = Blob.valueOf(encrypt.Name);
         Blob encryptedData = Crypto.encryptWithManagedIV('AES256', cryptoKey , data );
         String b64Data = EncodingUtil.base64Encode(encryptedData);
         encrypt.name = 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 ('https://ap5.salesforce.com/a00/o.jsp?password ');
      //  PageReference pg = new PageReference ('/apex/EncryptExtensioncls?pw={!encrypt.Password__c}&un={!encrypt.name}');        
      /*   PageReference pg = new PageReference ('/apex/EnD?pw={!b64Data2}&un={!b64Data}');            
            
         pg.setRedirect(true);
         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);
         
         encrypt.name = 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}');            
            
         pg.setRedirect(true);
         return pg; */
          
        return null; 

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


visuaforce:





<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}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
       
        
       
    </apex:form>

   
</apex:page>