How to get the MD5 hash of a string directly in the terminal?
Solution 1:
You can also say something like this :
~$ echo -n Welcome | md5sum
83218ac34c1834c26781fe4bde918ee4 -
It basically does the same thing as described by @enzotib, but is perhaps a bit simpler.
Solution 2:
Very simple, it accepts stdin, so
md5sum <<<"my string"
To avoid the trailing newline added by the shell:
printf '%s' "my string" | md5sum
Solution 3:
$ echo -n 123456 | md5sum | awk '{print $1}'
e10adc3949ba59abbe56e057f20f883e
you can create a shell script.
For example,the script name is md5.sh:
#!/bin/bash
echo -n $1 | md5sum | awk '{print $1}'
permission execute:
chmod +x md5.sh
Then:
$ md5.sh 123456
e10adc3949ba59abbe56e057f20f883e
If your system is macOS. You need to modify this script:
$ echo -n 123456 | md5 | awk '{print $1}'
e10adc3949ba59abbe56e057f20f883e
Solution 4:
openssl md5 filename
openssl sha1 filename
For string pipe the content using echo
echo -n 123456 | openssl md5
Solution 5:
Running md5sum with no arguments at all will cause it to read input from the terminal. Type or paste whatever you want, and when you are done, press ctrl-d
to end the input.