Created
July 25, 2013 20:29
-
-
Save andreluizf/6083451 to your computer and use it in GitHub Desktop.
MD5
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
package com.xkey.saxgeral.helpers; | |
import java.io.UnsupportedEncodingException; | |
import java.math.BigInteger; | |
import java.security.MessageDigest; | |
import java.security.NoSuchAlgorithmException; | |
import org.apache.logging.log4j.LogManager; | |
import org.apache.logging.log4j.Logger; | |
public class MD5Helper { | |
private static Logger log = LogManager.getLogger(MD5Helper.class); | |
public static String md5(String value) { | |
String md5 = ""; | |
MessageDigest md = null; | |
try { | |
md = MessageDigest.getInstance("MD5"); | |
} catch (NoSuchAlgorithmException e) { | |
log.error("Erro ao gerar MD5", e); | |
} | |
BigInteger hash = new BigInteger(1, md.digest(value.getBytes())); | |
md5 = hash.toString(16); | |
return md5; | |
} | |
public static void main(String[] args) throws NoSuchAlgorithmException, UnsupportedEncodingException { | |
String senha = "SenhaMuitoForte"; | |
String md5 = md5(senha); | |
String saida = "Entrada: " + senha + "\nSenha com MD5: " + md5; | |
System.out.println(saida); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment