MD5 Encryption Algorithm in java


Using java.security.MessageDigest liberary

   
        /**
	 * MD5 algorithm implementation for the encryption of a message
	 * @param messageToencrypt
	 * @return encrypted message
	 */
	private String getMD5Encryption(byte[] messageToencrypt){
		String encryptedString = null;
		try {
			MessageDigest md = MessageDigest.getInstance("MD5");
			md.update(messageToencrypt);
			byte[] thedigest = md.digest();
			StringBuffer sb = new StringBuffer();
			for (byte b : thedigest) {
                           sb.append(String.format("%02x", b & 0xff));
                         }
			encryptedString = sb.toString();
		} catch (NoSuchAlgorithmException e) {
		   e.printStackTrace();
		}
		
		return encryptedString;
	}

One thought on “MD5 Encryption Algorithm in java

Comments are closed.