Skip to content

Instantly share code, notes, and snippets.

@spot62
Created February 15, 2017 16:15
Show Gist options
  • Save spot62/c76a62e0658aca1c0dc94b007d7c09d7 to your computer and use it in GitHub Desktop.
Save spot62/c76a62e0658aca1c0dc94b007d7c09d7 to your computer and use it in GitHub Desktop.
Java MD5
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
public class Solution {
public static void main(String[] args) throws NoSuchAlgorithmException, UnsupportedEncodingException {
try {
Scanner in = new Scanner(System.in);
String text = in.nextLine();
java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5");
byte[] array = md.digest(text.getBytes());
StringBuffer sb = new StringBuffer();
for (int i = 0; i < array.length; ++i) {
sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1,3));
}
System.out.println(sb.toString());
}
catch (java.security.NoSuchAlgorithmException e) {
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment