Skip to content

Instantly share code, notes, and snippets.

@xiconet
Created January 9, 2017 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xiconet/34b410d925b092f3b9ea260877392d28 to your computer and use it in GitHub Desktop.
Save xiconet/34b410d925b092f3b9ea260877392d28 to your computer and use it in GitHub Desktop.
Checksum one-liners.
# bourne shell functions below take 1 argument, the file_to_hash.
# prints hex digest on stdout
md5() {
perl -MDigest::MD5=md5_hex -le'print md5_hex(<> or die)' "$1"
# ruby -rdigest/md5 -e"puts Digest::MD5.file'/dev/null'"
# python -sBc "import hashlib;print hashlib.md5(open('$1','rb').read()).hexdigest()"
# md5 "$1"|cut -d' ' -f4 # mac
# md5sum "$1"|cut -d' ' -f1 # linux
# openssl md5 "$1" | grep -o '[[:xdigit:]][[:xdigit:]]*$' | cat
}
sha1() {
perl -MDigest::SHA=sha1_hex -Xle'print sha1_hex(<> or die)' "$1"
# ruby -rdigest/sha1 -e"puts Digest::SHA1.file'$1'"
# python -sBc "import hashlib;print hashlib.sha1(open('$1','rb').read()).hexdigest()"
# shasum "$1"|cut -d' ' -f1 # mac
# sha1sum "$1"|cut -d' ' -f1 # linux
# openssl sha1 "$1" | grep -o '[[:xdigit:]][[:xdigit:]]*$' | cat
}
sha224() {
perl -MDigest::SHA=sha224_hex -le'print sha224_hex(<>or die)' "$1"
# ruby -rdigest/sha2 -e"puts Digest::SHA224.file'$1'"
# python -sBc "import hashlib;print hashlib.sha224(open('$1','rb').read()).hexdigest()"
# shasum -a224 "$1"|cut -d' ' -f1 # mac
# sha224sum "$1"|cut -d' ' -f1 # linux
# openssl dgst -sha224 "$1" | grep -o '[[:xdigit:]][[:xdigit:]]*$' | cat
}
sha256() {
perl -MDigest::SHA=sha256_hex -le'print sha256_hex(<>or die)' "$1"
# ruby -rdigest/sha2 -e"puts Digest::SHA256.file'$1'"
# python -sBc "import hashlib;print hashlib.sha256(open('$1','rb').read()).hexdigest()"
# shasum -a256 "$1"|cut -d' ' -f1 # mac
# sha256sum "$1"|cut -d' ' -f1 # linux
# openssl dgst -sha256 "$1" | grep -o '[[:xdigit:]][[:xdigit:]]*$' | cat
}
sha384() {
perl -MDigest::SHA=sha384_hex -le'print sha384_hex(<>or die)' "$1"
# ruby -rdigest/sha2 -e"puts Digest::SHA384.file'$1'"
# python -sBc "import hashlib;print hashlib.sha384(open('$1','rb').read()).hexdigest()"
# shasum -a384 "$1"|cut -d' ' -f1 # mac
# sha384sum "$1"|cut -d' ' -f1 # linux
# openssl dgst -sha384 "$1" | grep -o '[[:xdigit:]][[:xdigit:]]*$' | cat
}
sha512() {
perl -MDigest::SHA=sha512_hex -le'print sha512_hex(<>or die)' "$1"
# ruby -rdigest/sha2 -e"puts Digest::SHA512.file'$1'"
# python -sBc "import hashlib;print hashlib.sha512(open('$1','rb').read()).hexdigest()"
# shasum -a512 "$1"|cut -d' ' -f1 # mac
# sha512sum "$1"|cut -d' ' -f1 # linux
# openssl dgst -sha512 "$1" | grep -o '[[:xdigit:]][[:xdigit:]]*$' | cat
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment