How to MD5 a String

As a Linux and Unix user, I think to do “md5sum” for your files is just a piece of cake. We always to use md5sum command to check various files, such as a OS  disk image. But today I come to a problem,  some web site use the md5 of the user ID as the “Invitation code” 😕

I would like to take “calcifer” as the user ID, so how to generate the md5 code for such a string??

Let’s see the manual:

MD5SUM(1) User Commands MD5SUM(1)
NAME
md5sum – compute and check MD5 message digest
SYNOPSIS
md5sum [OPTION]… [FILE]…
DESCRIPTION
Print or check MD5 (128-bit) checksums. With no FILE, or when FILE is
-, read standard input.
-b, –binary
read in binary mode
-c, –check
read MD5 sums from the FILEs and check them
-t, –text
read in text mode (default)
MD5SUM(1) User Commands MD5SUM(1)
NAME md5sum – compute and check MD5 message digest
SYNOPSIS md5sum [OPTION]… [FILE]…
DESCRIPTION Print or check MD5 (128-bit) checksums. With no FILE, or when FILE is -, read standard input.
-b, –binary read in binary mode
-c, –check read MD5 sums from the FILEs and check them
-t, –text read in text mode (default)

Obviously, we can’t make it as the usual way we used to do  ….
So we have to do a litter small trick: using pipe ~

echo -n "calcifer" | md5sum - 

PS:  “-n” is to make sure we didn’t include the “new line” this invisible symbol .
So here can to the result:

calcifer@calcifer-laptop:~/Desktop$ echo -n "calcifer" | md5sum -

3ba9c9546d5dcb7ce2ee47967a83e324  - 

That’s what we need~~
And further more, it’s nautilus for some people to input the command like this:

 echo -n calcifer | md5sum 

In fact, the outcome is the same:

calcifer@calcifer-laptop:~/Desktop$ echo -n calcifer | md5sum -
3ba9c9546d5dcb7ce2ee47967a83e324  - 
Feb 26th, 2011 | Posted in Technique
No comments yet.

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Note: Commenter is allowed to use '@User+blank' to automatically notify your reply to other commenter. e.g, if ABC is one of commenter of this post, then write '@ABC '(exclude ') will automatically send your comment to ABC. Using '@all ' to notify all previous commenters. Be sure that the value of User should exactly match with commenter's name (case sensitive).