com.app.common.encrypt.Hash Maven / Gradle / Ivy
The newest version!
package com.app.common.encrypt;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
* @Description
* @Author
* @Date
**/
public class Hash {
public Hash() {
}
public static byte[] md5(byte[] array) {
String algorithm = "MD5";
return hash(array, algorithm);
}
public static byte[] sha(byte[] array) {
String algorithm = "SHA-1";
return hash(array, algorithm);
}
private static byte[] hash(byte[] array, String algorithm) {
try {
MessageDigest digest = MessageDigest.getInstance(algorithm);
digest.update(array);
return digest.digest();
} catch (NoSuchAlgorithmException var3) {
var3.printStackTrace();
return null;
}
}
}