当前位置:网站首页>SHA256加密工具类
SHA256加密工具类
2022-06-28 11:38:00 【一杯苦芥】
public class SHA256Util {
/**
* 用java原生的摘要实现SHA256加密
*
* @param str 加密前的报文
* @return
*/
public static String getSHA256String(String str) {
String encodeStr = "";
try {
MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
messageDigest.update(str.getBytes("UTF-8"));
encodeStr = byte2Hex(messageDigest.digest());
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return encodeStr;
}
/**
* byte[]转为16进制
*
* @param bytes
* @return
*/
private static String byte2Hex(byte[] bytes) {
StringBuffer stringBuffer = new StringBuffer();
for (int i = 0; i < bytes.length; i++) {
String temp = Integer.toHexString(bytes[i] & 0xFF);
if (temp.length() == 1) {
stringBuffer.append("0");
}
stringBuffer.append(temp);
}
return stringBuffer.toString();
}
}
边栏推荐
- JS foundation 10
- 6. calculation index
- day37 js笔记 运动函数 2021.10.11
- MapReduce project case 1
- What is DAPP system development and analytical understanding
- Cohere, a large model company, completed the round B financing of US $125million
- Ali three sides: what is the difference between using on or where in the left join associated table and the condition
- Allez, Meta - Cosme, comme prévu, cette chaleur ne durera pas longtemps.
- 【C语言】判断三角形
- Timestamp and date conversion "suggested collection"
猜你喜欢

Practice and Thinking on the architecture of a set of 100000 TPS im integrated message system

Fruit FL studio/cubase/studio one music host software comparison

QML control type: tabbar

Cannot redeclare block range variables

js中的数组方法 2021.09.18

day32 js笔记 事件(上)2021.09.27

day39 原型鏈及頁面烟花效果 2021.10.13

2018 joint examination of nine provinces & Merging of line segment trees

Self use demo of basic component integration of fluent

Graphics view framework for QT learning (to realize startup animation)
随机推荐
Pre parsing, recursive functions and events in day25 JS 2021.09.16
Day33 JS note event (Part 2) September 28, 2021
Source code analysis of ArrayList
Fruit FL studio/cubase/studio one music host software comparison
Data analysis learning notes
來吧元宇宙,果然這熱度一時半會兒過不去了
【C语言】如何产生正态分布或高斯分布随机数
. Net hybrid development solution 24 webview2's superior advantages over cefsharp
day31 js笔记 DOM下 2021.09.26
AcWing 604. Area of circle (implemented in C language)
Array method in JS 2021.09.18
Interview skills for interview steps
Simple understanding of ThreadLocal
Intranet penetration in the working group environment: some basic methods
Web page tips this site is unsafe solution
ArrayList源码解析
MapReduce project case 1
Characteristics of solar wireless LED display
If you want to change to software testing, how can you package your resume as a test engineer with 1 year of work experience
.NET混合开发解决方案24 WebView2对比CefSharp的超强优势