package com.itzcl;
import java.security.GeneralSecurityException;
import java.security.MessageDigest;
import java.security.ProviderException;
import org.apache.commons.codec.binary.Hex;
public class Demo {
public static void main(String[] args) {
String password = "12345";//需要sha-1加密的密码
byte[] bytes = password.getBytes();//将密码转换为byte数组
byte[] sha1 = sha1(bytes);//调用加密方法
char[] encodeHex = Hex.encodeHex(sha1);
System.out.println(new String(encodeHex));//输出结果转换
}
public static byte[] sha1(byte[] data) {
try {
MessageDigest md = MessageDigest.getInstance("SHA-1");
md.update(data);
return md.digest();
} catch (GeneralSecurityException var2) {
throw new ProviderException(var2);
}
}
}
jar包下载地址 :