2

I'm trying to compare a checksum to the checksum of the file but I'm getting the UTF- 8 string error.

 for(file thefile : list)
 {  
 thefile.checksum = Crypto.generateDigest('MD5',Blob.valueOf(thefile.encodedfile)).tostring();
 }

Any help is much appreciated on how to convert MD5 to string. Thanks!

2 Answers 2

1

I believe that what you want to do is get the hex values of the binary digest:

EncodingUtil.convertToHex(Blob MD5digest);

Documentation on this method can be found here.

Assuming that the checksum value was generated the same way, you should be able to use the string returned from convertToHex() for comparison:

thefile.checksum = EncodingUtil.convertToHex(Crypto.generateDigest('MD5',Blob.valueOf(thefile.encodedfile)));
0

Have you tried

for(file thefile : list)
{
    thefile.checksum= EncodingUtil.base64Encode(Crypto.generateDigest('MD5',Blob.valueOf(thefile.encodedfile));
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.