I don't want to calculate a file's checksum, just to know if a given string is a valid checksum
You can check using the following function: function isValidMd5($md5 ='') { return preg_match('/^[a-f0-9]{32}$/', $md5); } echo isValidMd5('5d41402abc4b2a76b9719d911017c592'); The MD5 (Message-digest algorithm) Hash is typically expressed in text format as a 32 digit hexadecimal number.
Type the following command: md5sum [type file name with extension here] [path of the file] -- NOTE: You can also drag the file to the terminal window instead of typing the full path. Hit the Enter key. You'll see the MD5 sum of the file. Match it against the original value.
SHA1 verifier:
public boolean isValidSHA1(String s) { return s.matches("^[a-fA-F0-9]{40}$"); }
MD5 verifier:
public boolean isValidMD5(String s) { return s.matches("^[a-fA-F0-9]{32}$"); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With