Jump to content
Praetorian503

[Java] Generate MD5 Hash

Recommended Posts

Posted

Here's the simple java security tutorial on generating MD5 hash of input text using java.security API functions.

import java.security.MessageDigest;

public class MD5Class
{
public static void main(String args[]) throws Exception
{
String input = "test text";

MessageDigest m = MessageDigest.getInstance("MD5");
m.update(input.getBytes("UTF8"));
byte s[] = m.digest();
String result = "";

for (int i = 0; i < s.length; i++)
{
result += Integer.toHexString((0x000000ff & s[i]) | 0xffffff00).substring(6);
}

System.out.println("MD5 Hash of input text" + input);
System.out.println(result);
}
}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...