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

MD5 Encode doesn't match expected result

I'm trying to MD5 encode a key for an external request. However, I must be doing something wrong because my key doesn't match the one that the service is expecting. I think it has something to do with having to make the string into a blob before using the generateDigest function.


Here's my code:


string keystring = 'StJoApuytj2ih48p3062010';
Blob keyblob = Blob.valueof(keystring);
Blob key = Crypto.generateDigest('MD5',keyblob);
System.Debug('Key: '+key.toString());

When I run this keystring through another website, I get this key: fdb338dff10d6619a3516b627ebbfc2c


When I run this keystring through Salesforce I get this: �8�� f�Qkb~��


Anybody know how to get them to match?

Best Answer chosen by Admin (Salesforce Developers) 

You probably need to call encodingUtil.convertToHex on the resulting blob.