· 7 years ago · Feb 24, 2018, 02:14 AM
1private String getMac(String RequestString, String secretkey) {
2String algorithmName = ‘hmacSHA1′; // the other options are: hmacMD5, hmacSHA256, and hmacSHA512
3Blob input = Blob.valueOf(RequestString);
4Blob signing =Crypto.generateMac(algorithmName, input, secretkey);
5String str=EncodingUtil.urlEncode(EncodingUtil.base64Encode(signing), ‘UTF-8′);
6
7String str=EncodingUtil.base64Encode(signing);
8
9string timestamp1 = datetime.now().formatGmt('EEE, d MMM yyyy HH:mm:ss Z');
10String action = 'Action';
11String algorithmName = 'HMACSHA256';
12Blob mac = Crypto.generateMac(algorithmName, Blob.valueOf(timestamp1),
13Blob.valueOf(Secretkey));
14String macUrl =EncodingUtil.base64Encode(mac);