Skip to content

Instantly share code, notes, and snippets.

@marcoslhc
Created October 14, 2012 22:45
Show Gist options
  • Save marcoslhc/3890047 to your computer and use it in GitHub Desktop.
Save marcoslhc/3890047 to your computer and use it in GitHub Desktop.
Various forms to create an unique identifier by hash digest
#Taken from http://stackoverflow.com/questions/8996820/how-to-create-md5-hash-in-bash-in-macos
echo "this will be encrypted" | md5
# 72caf9daf910b5ef86796f74c20b7e0b
md5 <<< 'this will be encrypted'
# 72caf9daf910b5ef86796f74c20b7e0b
md5 -s 'this will be encrypted'
# MD5 ("this will be encrypted") = 502810f799de274ff7840a1549cd028a
md5 -qs 'this will be encrypted'
# 502810f799de274ff7840a1549cd028a
#######
# Note: MD5 always produces the same hash. The reason you find the output different from the example given above is due to a
# point that has been made in the comments. The first two examples use the trailing newline character to produce the hash. To
# avoid that, you can use:
#######
echo -n "this will be encrypted" | md5
# 502810f799de274ff7840a1549cd028a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment