0% found this document useful (0 votes)
24 views1 page

@author /: Import

This Java class contains methods to encrypt strings using the MD5 algorithm. The cifrarMD5 method takes a password string as input, encrypts it using MD5, and returns the encrypted string. It catches any NoSuchAlgorithmExceptions. The byteArrToString method converts an array of bytes to a hexadecimal string for the encrypted output.

Uploaded by

StivennMendez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views1 page

@author /: Import

This Java class contains methods to encrypt strings using the MD5 algorithm. The cifrarMD5 method takes a password string as input, encrypts it using MD5, and returns the encrypted string. It catches any NoSuchAlgorithmExceptions. The byteArrToString method converts an array of bytes to a hexadecimal string for the encrypted output.

Uploaded by

StivennMendez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

1 /*

2 * To change this template, choose Tools | Templates


3 * and open the template in the editor.
4 */
5 package gestionusuarios.jsf.controladores.util;
6
7 import java.security.*;
8
9 /**
10 *
11 * @author
12 */
13 public class AlgoritmoMD5 {
14
15 public static String cifrarMD5(String strContrasena) {
16 String strContrasenaMD5 = null;
17 try {
18 MessageDigest md5 = MessageDigest.getInstance("MD5");
19 byte[] tmp = strContrasena.getBytes();
20 md5.update(tmp);
21 strContrasenaMD5 = byteArrToString(md5.digest());
22 } catch (NoSuchAlgorithmException ex) {
23 strContrasenaMD5 = null;
24 }
25 return strContrasenaMD5;
26 }
27
28 private static String byteArrToString(byte[] b) {
29 String res = null;
30 StringBuilder sb = new StringBuilder(b.length * 2);
31 for (int i = 0; i < b.length; i++) {
32 int j = b[i] & 0xff;
33 if (j < 16) {
34 sb.append('0');
35 }
36 sb.append(Integer.toHexString(j));
37 }
38 res = sb.toString();
39 return res.toUpperCase();
40 }
41
42 }
43

You might also like