MD5 Hash Encryption

 I want to hash each line separately


What is MD5?
      Hachage functions.
      Other functions.
Applications of MD5 Hash
     MD5 Hash in the storage of passwords.
     MD5 Hash to check File Integrity.
     MD5 Hash in data or file identification.
Practical examples codes
     SGBD & system (Unix/PstgreSQL/OpenSSL/..).

What is MD5?

MD5 (Message Digest algorithm 5) finds its wide applicable use in cryptographic hash functions since its 1991 invention by Ronald Rivest.

The ideology of the algorithm is to accept the input of a random data and generate an output of a fixed size “hash value”. The length or size of the input data varies while the “hash value” output size remains fixed. A working example of the MD5 Hash function is highlighted.

A 32 digit hex MD5 is always an output of the fixed generated algorithm.


Applications of MD5 Hash

When you think of MD5 hash algorithm, a 32 digit hexadecimal number should pope up in your head.

Something like :


The uniqueness of the hash is irrespective of the type and size of the file. An example would be two distinct but similar in size executable files (.exe files). Their MD5 hash would be dissimilar despite their similarity in size and type. The above statement thus yields the applicability of MD5 hash in the unique identification of a file. The applicability also applies to the verification of sent and received messages through the MD5 hash.

  MD5 Hash in the storage of passwords

Password storage is also an applicability of MD5 hashes. The storage of passwords in the database in texts forms is never a brilliant idea in terms of security. The hash values conversion thus comes in handy for the obvious stated reason. The password input by the user leads to a hash value conversion and a check performed in comparison to the stored hash. Since the hashing process is a one-way journey, provided that a sound algorithm is in place, theory would chance a zero probability towards deciphering the original password from the hash. The generation of passwords is also evident through cryptographic hashing, and the derivation of singular phrased passwords also follows suit.

  MD5 Hash to check File Integrity

Suppose there exists a backup.tar file on your server. The generation of MD5 hash should be mandatory prior to the download of the file. To accomplish the task, the following command should come in hand while on your UNIX terminal.

md5sum backup.tar

Once you press the ENTER button, something like this should be displayed.


The generated output represents the MD5 hash for the backup.tar file. After a successful download of the file on your PC, re-generating the MD5 hash again will enable you to cross check on the file’s integrity. A match on both the MD5 hash will pre-determine if the file is still in a perfect state or unaltered. Another outcome will only imply that the file is corrupt.

For a Windows PC user, the verification of the file can be performed using MD5 Summer software.

  MD5 Hash in data or file identification

The MD5 hashing algorithm is also significant in the identification of data or file. An exemplary application would be in the file sharing networks (peer to peer), with eDonkey2000 as an example. The combination of the file size as displayed below through the MD5 algorithm variant use by the system is prompt to point out the hash files available on the network.

Its applicability is also in the functionality of search engines where a signature example is in its quick prompt to locate data in hash tables.




  • The algorithm in use is reputable due to its fast computation.

  • The provision of collision resistance ensures that the assessed data does not alter the structure and format of any simultaneous data or file in place.

  • The algorithm has a widespread global use and hence a supportive community on its undertaking.

  • Due to the provision of a one way hash sequence it is almost impossible to decipher the algorithm and hence security check is guaranteed.


  • A rumble in the security community about MD5 and its weaknesses has made it vulnerable to security flaws.

  • In comparison to the SHA-1algorithm, the security flaws of MD5 appear to be magnified in terms of vulnerability.

Practical examples codes


string md5
( string $str, bool $raw_output = false )
str: a string to hash.
raw_output: raw_output = TRUE -> binairy result

    $str = 'Your_password';
    $str_hashed = md5($str);
    echo $str_hashed;      // 3df11a12265e10434edcbea4de121dec


Lib/ : This module implements a common interface to many different secure hash and message digest algorithms.
Included are hash algorithms: SHA1, SHA224, SHA256, SHA384, and SHA512 as well as RSA’s MD5 algorithm.

    >>> import hashlib
    >>> m = hashlib.md5()
    >>> m.update("Your_password")
    >>> print m.hexdigest() # 3df11a12265e10434edcbea4de121dec


System.Security.Cryptography : Name space providing encryption services, including secure data coding and decoding.
It also presents plenty of other functionalities like hashing, random numbers generation and authentication messages.

    using System.Security.Cryptography.MD5;

    namespace MD5Sample
      class Program
        static void Main(string[] args)
          string pass = "Your_password";
          MD5 md5Hash = MD5.Create();
          // Calculate MD5 hash from input
          byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(pass));
          StringBuilder sBuilder = new StringBuilder();
          // Convert byte array to hex string
          for (int i = 0; i < data.Length; i++)
          string hash = sBuilder.ToString();
          Console.WriteLine(hash); // 3df11a12265e10434edcbea4de121dec



Linux commands:

    [root@servername ~] pass="Your_password"
    [root@servername ~] hash="$(echo -n "$pass" | md5sum )"
    [root@servername ~] echo "$hash"


This module provides a framework for message digest libraries.

    require 'digest/md5'
    hash = Digest::MD5.hexdigest('Your_password')
    puts hash # 3df11a12265e10434edcbea4de121dec


jQuery doesnt have a method to provide the md5 of a string. So you need to use some external script.
There is a plugin called "jQuery-MD5".

    var Pass = "Your_password";
    var md5 = $.md5(Pass);
    console.log(md5); // 3df11a12265e10434edcbea4de121dec

  OPENSSL in C++


    main() {

        unsigned char digest[MD5_DIGEST_LENGTH];
        char pass[] = "Your_password";
        MD5((unsigned char*)&pass, strlen(pass), (unsigned char*)&digest);    
        char hash[33];
        for(int i = 0; i < 16; i++)
            sprintf(&hash[i*2], "%02x", (unsigned int)digest[i]);
    printf("%s", hash); // 3df11a12265e10434edcbea4de121dec


Modules :
The "Digest::MD5" module allows you to use the RSA Data Security Inc. MD5 Message Digest algorithm from within Perl programs. The algorithm takes as input a message of arbitrary length and produces as output a 128-bit "fingerprint" or "message digest" of the input.

    use Digest::MD5;
    $md5 = Digest::MD5->new;
    $hash = $md5->hexdigest;
    print "$hash"; # 3df11a12265e10434edcbea4de121dec


Lib/ : This module implements a common interface to many different secure hash and message digest algorithms.
Included are hash algorithms: SHA1, SHA224, SHA256, SHA384, and SHA512 as well as RSA’s MD5 algorithm.

    SELECT MD5('Your_password') as hash;  -- 3df11a12265e10434edcbea4de121dec

  • Message Digest algorithm 5 finds its wide applicable use in cryptographic hash functions since its 1991 invention by Ronald Rivest.
    The ideology of the algorithm is to accept the input ... Show more

  • 128 bits length is equivalent to MD5 while 160 bits length is equivalent to SHA1. Thus, the possibility of MD5 hashes is 2128 while the possibility of SHA1 hashes is 2160. The large number is reasonable enough ... Show more

  • The creation of Secure Hash Algorithm (SHA) was realized in 1993 by NIST (National Institute of Standard and Technology). The discovery of a flaw soon unraveled after its creation. The mother version... Show more

  • Proin a velit aliquam vitae malesuada rutrum. Aenean ullamcorper placerat porttitor velit aliquam vitae. Aliquam a augue suscipit, bibendum luctus neque laoreet rhoncus ipsum, ullamcorper ... Show more

  • A hash function is simply any function used in the mapping of data from an arbitrary size to a fixed size. Simply hashes, hash sums, hash codes, or hash values are the return values from the hash function..... Show more

Newsletter Subscription

Be amongst the first to know about our services, ideas and latest features

Get in touch

We will get back to you as soon as possible