Created
June 29, 2015 14:29
-
-
Save dbbrian/e8fc4048a86acf2798d9 to your computer and use it in GitHub Desktop.
Simple bash script that print the SHA* of the given string, defaults to SHA1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Print the SHA* of the given string, defaults to SHA1 | |
# | |
# $method, $string | |
print_digest() | |
{ | |
echo -n "$2" | openssl dgst "$1" | cut -f 1 -d " " | |
} | |
case "$1" in | |
-0| --sha| -sha) print_digest "-sha" "$2" ;; | |
-1| --sha1| -sha1) print_digest "-sha1" "$2" ;; | |
-224|--sha224|-sha224) print_digest "-sha224" "$2" ;; | |
-256|--sha256|-sha256) print_digest "-sha256" "$2" ;; | |
-384|--sha384|-sha384) print_digest "-sha384" "$2" ;; | |
-512|--sha512|-sha512) print_digest "-sha512" "$2" ;; | |
-?*) echo "Unknown digest: \"$1\"" ; exit 1 ;; | |
*) print_digest "-sha1" "$1" ;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment