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
Nish321Nish321 

HMAC encrytion

Hi, 
I'm trying to encrypt json data by signing with HMAC. Code doesn't seem to generate the right link.  Please assist !! 
 
public class crypto1 
    {
    
				 public string encryptkeyy = '3kXLV1rnimLRd0of4TPGz7iu2Wdd+/hYdfdf/Dt6nnIk=';  
				 public string authkeyy =     '2BKulGe3CTWOxSHkwR6546XqkM62dNpFAeuuWhfevc4A=';
				 public string domain = 'XYZ.com';
				
				 
				 public void crpytofunction(){
				 
				 string order   = '{ "email":"john@doe.com","name":"John Doe","ref":"1234"}';
				 
				
				
				 
				
				
				Blob encKey = EncodingUtil.base64Decode(encryptkeyy );
			  
				
				
				 Blob authKey = EncodingUtil.base64Decode(authkeyy);
				
				
				Blob data = Blob.valueOf(order);
				
			   // string s =  String.valueOf(Crypto.getRandomInteger());

				
				//Initialization vector
				  Blob encryptedBlob = Crypto.encryptWithManagedIV('AES256',authKey,data);
				  
			  
				  String encodedCipherText = EncodingUtil.base64Encode(encryptedBlob );  // all good until here .. 
				   
				   string payload = EncodingUtil.urlEncode(encodedCipherText,'UTF-8');
				   
				   Blob data1 = crypto.generateMac('HmacSHA256', encryptedBlob, authKey );  // problem with this part. 
				   
				   String anotherone = EncodingUtil.base64Encode(data1);
			
			  
					string link =  'https://www.trustpilot.com/evaluate-bgl/xyz.com?'+anotherone

     
    } 
    
   
      
    
    
    }

 
sudha rani 13sudha rani 13

Hi Nish

Did you get the answer?

I am also looking for the same.