血缘解析
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
982 B

package com.guozhi.bloodanalysis.utils;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class EncryptUtils {
public static String encryptSHA256(String str){
return sha("SHA-256",str);
}
private static String sha(String type,String str){
String result = null;
try {
MessageDigest md = MessageDigest.getInstance(type);
md.update(str.getBytes());
byte[] byteBuffer = md.digest();
StringBuilder strHexString = new StringBuilder();
for (byte b : byteBuffer) {
String hex = Integer.toHexString(0xff & b);
if (hex.length() == 1) {
strHexString.append('0');
}
strHexString.append(hex);
}
result = strHexString.toString();
}catch (NoSuchAlgorithmException e){
e.printStackTrace();
}
return result;
}
}