public static String sha1(String input, String charset) throws NoSuchAlgorithmException, UnsupportedEncodingException {
if (input == null) {
return null;
}
MessageDigest md;
md = MessageDigest.getInstance("SHA-1");
return hexFormat(md.digest(charset==null?input.getBytes():input.getBytes(charset)));
}
private static String hexFormat(byte hash[]){
Formatter formatter = new Formatter();
try {
for (byte b : hash) {
formatter.format("%02x", b);
}
return formatter.toString();
} finally {
formatter.close();
}
}
分享一个在线转码,IP定位小工具——头条在线工具
java对字符串进行SHA1加密
最新推荐文章于 2023-05-25 10:33:15 发布