This online tool generates MD5 hash codes for the given text. Read further to get the source code for the MD5 hash code generator in .NET, Java and PHP.
This tool generates MD5 hash codes from the entered text.
MD5 is otherwise called as Message-Digest 5 Algorithm. This cryptographic algorithm is widely used to cross verify the data integrity. The MD5 algorithm computes and generates a hexadecimal number for text or binary value. This hexadecimal number is 36 digits long, i.e. 128 bit. The length of this hexadecimal hash code will be the same even if the input is 2 character string or 10,000 character text. For example, the MD5 hash code for www.mytecbits.com is 8533baebba27067f05b73c760b332112.
MD5 hashing algorithm cannot be used for high security encryptions as there where flaws in the design which lead to hacking. So, nowadays high security applications uses SHA-1 and SHA-2 hashing algorithm. This does not mean we should not use MD5, instead we can use MD5 hashing for low profile usage like data validation, file validation, etc...
Major programming languages has inbuilt MD5 classes to generate and verify MD5 hash codes.
.Net has System.Security.Cryptography.MD5 abstract class. This class has ComputeHash(Byte[]), ComputeHash(Stream) and ComputeHash(Byte[], Int32, Int32) methods which can be used to generate MD5 hash codes.
Below is a simple .Net C# class method which takes a string as input and returns MD5 hash code.
public static string Generate(string strInput) { MD5 md5 = new MD5CryptoServiceProvider(); //provide the string in byte format to the ComputeHash method. //This method returns the MD5 hash code in byte array byte[] arrHash = md5.ComputeHash(Encoding.UTF8.GetBytes(strInput)); // use a Stringbuilder to append the bytes from the array to create a hash code string. StringBuilder sbHash = new StringBuilder(); // Loop through byte array of the hashed code and format each byte as a hexadecimal code. for (int i = 0; i < arrHash.Length; i++) { sbHash.Append(arrHash[i].ToString("x2")); } // Return the hexadecimal MD5 hash code string. return sbHash.ToString(); }
In Java you can use the MessageDigest abstract class to generate the MD5 hash code for a string
Below is a simple java class method which takes a string as input and returns MD5 hash code.
import java.math.BigInteger; import java.security.MessageDigest; public class MD5 { public static String GenerateHash(String input) { MessageDigest objMD = MessageDigest.getInstance("MD5"); byte[] bytMD = mobjMDd.digest(input.getBytes()); BigInteger intNumber = new BigInteger(1, bytMD); String strHashCode = intNumber.toString(16); // pad with 0 if the hexa digits are less then 32. while (strHashCode.length() < 32) { strHashCode = "0" + strHashCode; } return strHashCode; } }
PHP has MD5() method to calculate MD5 hash code.
<?php $str = "www.MyTecBits.com"; echo md5($str); ?>
Page Last Modified On: Jul 23, 2021
Disclaimer: We took every effort to provide higher level of accuracy in the calculators, converters and tools we have added to www.MyTecBits.com Tools section. But, we cannot give any guarantee or can be held responsible for any errors, defects, faults or mistakes in any of the calculators, converters or tools. Please see detailed terms of use and liability disclaimer in Terms of Use Page.