Вопрос

I'm trying to generate an HMAC value within Salesforce using the Crypto generateMac function, but the result doesn't match with other utilities.

For example, I'm trying to hash the value Hash me using the key ac67ad3b8771bf63d4fa9582845a18f921514f36. I'm expecting the result to be 66fe419859ac42ad88354dfa52f2196a26d767e1, but it's actually 7d1f56c728dfefdcb9edb72b7c0c8df2acf1cae9.

My apex code is:

Blob mac = Crypto.generateMac('HMacSHA1', Blob.valueOf('Hash me'),
    Blob.valueOf('33a1211c0ee01511ccba1e456bb95503')); 
string hasedValue = EncodingUtil.convertToHex(mac);

I'm guessing the issue is related to converting to/from binary or maybe related to case, but I cannot match the expected result.

My expected result is based on the result from http://hash.online-convert.com/sha1-generator and a couple other online HMAC calculators.

Это было полезно?

Решение

The other option is to do a base 64 encode:

EncodingUtil.base64Encode(mac);

I'd be surprised if generateMac + convertToHex aren't working for you. They've always worked for me. I'm sure you've looked, but just in case I'd go over the Amazon web services example in the documentation.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top