当前位置:网站首页>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();
}
}
边栏推荐
- 【C语言】如何产生正态分布或高斯分布随机数
- 3. seat number
- NFT card chain game system development DAPP construction technical details
- Interview skills for interview steps
- MapReduce project case 3 - temperature statistics
- 6.A-B
- On the output representation of bidirectional LSTM in pytoch
- Is it safe to buy stocks and open an account on the account QR code of the CICC securities manager? Ask the great God for help
- Is it feasible to be a programmer at the age of 26?
- Build your own website (18)
猜你喜欢

Remote login sshd service

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

Using soapUI to obtain freemaker's FTL file template

Software test interview classic + 1000 high-frequency real questions, and the hit rate of big companies is 80%

day29 js笔记 2021.09.23

Leetcode 48. 旋转图像(可以,已解决)

Web page tips this site is unsafe solution

Everyone can participate in open source! Here comes the most important developer activity in dragon lizard community

Characteristics of solar wireless LED display

携手Cigent:群联为SSD主控固件引入高级网络安全防护特性
随机推荐
AcWing 609. Salary (implemented in C language)
Interview skills for interview steps
【C语言】如何很好的实现复数类型
Random forest and poetry maker trained by AMR
【C语言】随机数文件对其进行三种排序方法
Day30 JS notes BOM and DOM 2021.09.24
Oracle date format exception: invalid number
Zero basic C language (I)
Daily practice of C language - day 4: find the sum of all even numbers within 100
1. print hourglass
AGCO AI frontier promotion (2.16)
Django -- MySQL database reflects the mapping data model to models
4. maximum continuity factor
Prefix and (2D)
fatal: unsafe repository (‘/home/anji/gopath/src/gateway‘ is owned by someone else)
IO stream of file and Base64
AcWing 606. Average 1 (implemented in C language)
[sciter]: how sciter uses i18 to realize multi language switching of desktop applications and its advantages and disadvantages
QML控件类型:TabBar
Day29 JS notes 2021.09.23