Rev 182 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 178 | espaco | 1 | package br.com.ec.core.util; |
| 2 | |||
| 3 | import java.math.BigInteger; |
||
| 4 | import java.security.MessageDigest; |
||
| 5 | |||
| 6 | public class RashMD5 { |
||
| 7 | |||
| 8 | private static final String ERRO_AO_GERAR_RASH = "Erro ao gerar rash."; |
||
| 9 | private static final String COMPLETAR_RASH_MD5_COM_ZERO = "0"; |
||
| 10 | private static final String TIPO_RASH_MD5 = "MD5"; |
||
| 11 | |||
| 12 | public static String gerarRash (String string){ |
||
| 13 | if(string != null){ |
||
| 14 | try { |
||
| 15 | MessageDigest md = MessageDigest.getInstance(TIPO_RASH_MD5); |
||
| 16 | BigInteger hash = new BigInteger(1, md.digest(string.getBytes())); |
||
| 17 | String senhaCriptografada = hash.toString(16); |
||
| 18 | if (senhaCriptografada.length() %2 != 0) { |
||
| 19 | senhaCriptografada = COMPLETAR_RASH_MD5_COM_ZERO + senhaCriptografada; |
||
| 20 | } |
||
| 21 | return senhaCriptografada; |
||
| 22 | }catch (Exception e) { |
||
| 23 | throw new RuntimeException(ERRO_AO_GERAR_RASH); |
||
| 24 | } |
||
| 25 | } |
||
| 26 | return null; |
||
| 27 | } |
||
| 28 | |||
| 29 | } |