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


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)));

Have you tried

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .