As a developer/admin, sometimes you might have to generate the MD5 hash of a string. Eg. last time I had to do this, when I installed the admin interface of
XCache on a server. I had to create an MD5 of the admin password and put it into xcache.ini. The docs said that I should create a PHP file with something like
<?php echo md5('the_password'); ?> to get the MD5 hash. However there's a much faster way, a simple command line.
If you're a regular linux user (or admin) you've probably already met the
md5sum command. This was meant to generate (and compare) MD5 hashes of files. However you can generate the MD5 hash of data coming from standard input too. You just have to be careful that the input you provide to
md5sum is indeed what you meant.
Here's a command line that'll work in most cases:
echo -n 'the_password' | md5sum -
I wrote "most cases", because I used the
-n switch of the
/bin/echo command in the above example to force
echo not to add a newline character automatically behind the string I supplied. Now in your case
echo might refer to a shell builtin or have different switches. The point is to make sure that
md5sum really gets only the string that you intended.
PS: using the various
sha*sum commands (sha1sum, sha256sum, sha512sum, ...) you can use this method to generate various SHA hashes. These commands (md5sum, sha*sum) are all part of the
coreutils package (Debian, Ubuntu) and are probably part of most linux distributions nowadays. Chances are high that they are all available on your linux setup too.
Comments
Or use perl perl
perl -MDigest::MD5 -le 'print Digest::MD5->md5_base64("the_password")'Re: Or use Perl
Bash History
rm ~/.bash_history
...when you are done to avoid someone seeing your password in plaintext if the development system is a shared box.
Re: Bash History
HISTFILEenvironment variable. Like:unset HISTFILEPython
>>> import hashlib>>> hashlib.md5(b"secretstring").hexdigest()
CMD.exe
Could not pipe string into md5sums without extra characters