Skip to content

Instantly share code, notes, and snippets.

@eos87
Created October 21, 2010 05:01
Show Gist options
  • Save eos87/637971 to your computer and use it in GitHub Desktop.
Save eos87/637971 to your computer and use it in GitHub Desktop.
md5
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package utils;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.logging.*;
/**
*
* @author e0s87
*/
public class Codificador {
/** * Clase con métodos estáticos de cifrado * */
public String getEncoded(String texto, String algoritmo) {
String output="";
try {
byte[] textBytes = texto.getBytes();
MessageDigest md = MessageDigest.getInstance(algoritmo);
md.update(textBytes);
byte[] codigo = md.digest();
output = new String(codigo);
} catch (NoSuchAlgorithmException ex) {
Logger.getLogger(Codificador.class.getName()).log(Level.SEVERE, null, ex);
}
return output;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment