ASObjC Equivalent to MD5

Is there some way to get a checksum for a file with ASObjC in the same fashion as the md5 utility? Right now I will use the answer to check JPG files for equality, but I’m primarily interested in the answer just for learning purposes. Thanks.

1 Like

Are any of the Objective C methods useful? ‘Generate MD5’ on developer.apple.com

1 Like

If you a wanting to compare the equality of the fies, perhaps sha1 would be useful:
set mySha to (do shell script "echo ‘full/image/path’ | openssl sha1")

1 Like

Thanks Paul and ralphcr for the responses.

I looked at the documentation Paul linked and did a Google search. CryptoKit seems ideal but that’s only available with Swift. I did find the following comment in a post somewhere, but I don’t know if this could be implemented with ASObjC:

If you want to create a MD5 from a file with these methods, then you can do NSData *fileContents = [NSData dataWithContentsOfFile:@“”]; NSString *myHash = [fileContents md5]; And yes, this would pull the whole file into memory. If you find a solution that works with file streams, please post it as an answer.

I queried Google Gemini AI and got full Objective-C code that apparently will create an MD5 checksum for a file, but, even if feasible, converting it to ASObjC code is beyond my abilities.

For JPG images, exiftool will return md5 checksums, but I suspect speed would be an issue.

I did try sha1 with do shell script. This works well and is a good solution, although when working with thousands of files the do shell script command slows things somewhat. Anyways, this is the solution I will use for now.