java实现的各种hash加密public class jiami {
public static void main(String args[]){
String signString="Thank you!";
String type="SHA-1";
String result=sign(signString,type);
System.out.println("采⽤"+type+"加密之后的串为:"+result);
type="MD5";
result=sign(signString,type);
System.out.println("采⽤"+type+"加密之后的串为:"+result);
type="SHA-256";
result=sign(signString,type);
System.out.println("采⽤"+type+"加密之后的串为:"+result);
type="SHA-384";
result=sign(signString,type);
System.out.println("采⽤"+type+"加密之后的串为:"+result);
}
//签名
public static String sign(String str, String type){
String s=Encrypt(str,type);
return s;
}
public static String Encrypt(String strSrc, String encName) {
MessageDigest md = null;
String strDes = null;
byte[] bt = Bytes();
java加密方式有哪些try {
md = Instance(encName);
md.update(bt);
strDes = bytes2Hex(md.digest()); // to HexString
} catch (NoSuchAlgorithmException e) {
System.out.println("签名失败!");
return null;
}
return strDes;
}
public static String bytes2Hex(byte[] bts) {
String des = "";
String tmp = null;
for (int i = 0; i < bts.length; i++) {
tmp = (HexString(bts[i] & 0xFF));
if (tmp.length() == 1) {
des += "0";
}
des += tmp;
}
return des;
}
}
还有  type="SHA-512";

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。