File Hash Extension

I'm looking for an extension that can calculate the hash of a file. (Preferably SHA256 but any should work.) I've searched the forum and checked Taifun's list and only found extensions to hash strings, not files.

You can get a sha256 hash of a file by using @Juan Antonio's Terminal extension.

sha256sum /absolute/path/to/file

Tested using companion 2.62u on Android 12 device.

If this is what you want, I have made an extension:
uk.co.metricrat.getfilesha256.aix (5.3 KB)

now added sha512 as well
uk.co.metricrat.getfilesha256V0.2.aix (5.4 KB)

5 Likes

This works pretty well (in the companion anyway, haven't checked it in a compiled APK), though I did need to use these blocks to get a full path to pass to the block.

Also, this extension is insecure when used with untrusted input.
image

This clearly shows that the command is being executed in a shell (If the text $(echo --help) was passed directly there would just be a file not found error) and expansions like that could mess things up or do malicious things. However this also provides a pretty good way of escaping file names, Never mind, I was going to base64 encode the filenames and pass them as $(echo <base64_encoded_filename> | base64 -d) to prevent unintended side effects but there's no block or extension I could find to base64 encode text so that won't work. Oh well.
This will probably work though

Base64 text encoding extension
uk.co.metricrat.justbase64.aix (4.0 KB)

3 Likes

Thanks, I think the blocks I included in my post will work though. I got my app working! It uploads photos to Google Photos without needing Play Services installed. The file hasher was needed to prevent duplicate uploads and it seems to be working great so far. Thank you so much for the extension!

1 Like