Created
November 22, 2013 23:36
-
-
Save eytanbiala/7608702 to your computer and use it in GitHub Desktop.
Calculates the MD5 hash of str using the RSA MD5 Message-Digest Algorithm, and returns that hash.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.security.*; | |
public class Secure { | |
public static void main(String[] args) { | |
final String pass = "password"; | |
String encrypted = MD5(pass); | |
System.out.println("Encrypted password: " + encrypted); | |
} | |
public static String MD5(String md5) { | |
try { | |
java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5"); | |
byte[] array = md.digest(md5.getBytes()); | |
StringBuffer sb = new StringBuffer(); | |
for (int i = 0; i < array.length; i++) { | |
sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1,3)); | |
} | |
return sb.toString(); | |
} catch (java.security.NoSuchAlgorithmException e) { | |
} | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment