How to generate secure password using MD5 in java

How To Generate Secure Password Using MD5 In Java


public class SimpleMD5
public static void main(String[] args)
System.out.println(“new password= “+SimpleMD5.getencrypt(“psaaword”));

public static String getencrypt(String passwordToHash){

String generatedPassword = null;
try {
// Create MessageDigest instance for MD5
MessageDigest md = MessageDigest.getInstance(“MD5”);
//Add password bytes to digest
//Get the hash’s bytes
byte[] bytes = md.digest();
//This bytes[] has bytes in decimal format;
//Convert it to hexadecimal format
StringBuilder sb = new StringBuilder();
for(int i=0; i< bytes.length ;i++)
sb.append(Integer.toString((bytes[i] & 0xff) + 0x100, 16).substring(1));
//Get complete hashed password in hex format
generatedPassword = sb.toString();
catch (NoSuchAlgorithmException e)
return generatedPassword;




new password= a52693edc4621e5a3078e01971ac1fdc


Leave a Reply

Your email address will not be published. Required fields are marked *

35 + = 44