MD5 Encryption using jQuery

Yesterday I needed to convert an input value to MD5 encrypted value using jQuery and sent to the server. jQuery library doesn't provide a function for MD5 encryption however there are some plugins available which can help. So in today post, I will show you how can you convert to MD5 using 2 different jQuery plugins which are "jQuery MD5 Plugin" and "jQuery Crypt Plugin".

What is MD5?

  • MD5 encryption is a one-way encryption algorithm.
  • Encrypted value return by MD5 encryption can't not be revert back to original value.
  • MD5 encryption will always return same encrypted value for same input value. For example, for value "jquery", it will always return "d223e1439188e478349d52476506c22e" as 16 byte hash value.

Using jQuery MD5 Plugin

Well, you don't have to much to convert input value to MD5 hash value while using this plugin. It is pretty straight forward. All you need to do is to make a call to $.md5(string) function and pass input value as argument. And in return, it will give MD5 encrypted value.

var strMD5 = $.md5(strVal);

See result below
(Update: Demo is not working due to some problem from JSFiddle, but the plugin is live. You can download it and use above code.)

Using jQuery Crypt Plugin

This plugin easily encodes MD5 and SHA1 as well as encoding and decoding of Base64 and Xtea strings. But right now, we are interested in MD5. So to convert it into MD5, call "$().crypt()" function and pass algorithm name which is "md5" and value that needs to be encrypted.

var strMD5 = $().crypt({
                method: "md5",
                source: strVal

See result below

There is not much difference between these 2 plugins and both will serve your purpose. But first plugin is completely related with MD5 where Crypt plugin also allows encoding and decoding of Base64 and Xtea strings.

Feel free to contact me for any help related to jQuery, I will gladly help you.

Responsive Menu
Add more content here...