import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
*
* @author Faith
*/
public class Encrypt {
public static String sha512(String cadena){
StringBuilder sb = new StringBuilder();
try {
MessageDigest md = MessageDigest.getInstance("SHA-512");
md.update(cadena.getBytes());
byte[] mb = md.digest();
for (int i = 0; i < mb.length; i++) {
sb.append(Integer.toString((mb[i] & 0xff) + 0x100,16).substring(1));
}
} catch (NoSuchAlgorithmException ex) {
}
return sb.toString();
}
}
Este fragmento de código contiene un método que recibe como parámetro una cadena para cifrarlo con SHA512.
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.