当前位置:网站首页>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();
}
}
边栏推荐
- QML控件类型:TabBar
- [Beijing University of Aeronautics and Astronautics] information sharing for the first and second examinations of postgraduate entrance examination
- Deployment and optimization of vsftpd service
- AcWing 604. Area of circle (implemented in C language)
- The default point of this in JS and how to modify it to 2021.11.09
- 【C语言】随机数文件对其进行三种排序方法
- 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
- Unity屏幕截图功能
- Contract quantitative trading system development | contract quantitative app development (ready-made cases)
- [sciter]:sciter如何使用i18实现桌面应用多语言切换及其利弊
猜你喜欢
![Connectionreseterror: [winerror 10054] the remote host forced an existing connection to be closed](/img/9a/97813f5ac4d7c15711891cff25b9dd.jpg)
Connectionreseterror: [winerror 10054] the remote host forced an existing connection to be closed

Day32 JS note event (Part 1) September 27, 2021

Web3 security serials (3) | in depth disclosure of NFT fishing process and prevention techniques
Three ways to implement LRU cache (recommended Collection)

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

day29 js笔记 2021.09.23
Using MySQL database in the express framework of node

Leetcode 705. 设计哈希集合

Still using simpledateformat for time formatting? Be careful that the project collapses!

If you want to change to software testing, how can you package your resume as a test engineer with 1 year of work experience
随机推荐
Day37 JS note motion function 2021.10.11
Web3 security serials (3) | in depth disclosure of NFT fishing process and prevention techniques
day39 原型链及页面烟花效果 2021.10.13
Come on, yuanuniverse. Sure enough, the heat won't pass for a while
js中this的默认指向及如何修改指向 2021.11.09
js中的class类模式及语法 2021.11.10
Simulation of the Saier lottery to seek expectation
MySQL cannot query the maximum value using the max function
Practice and Thinking on the architecture of a set of 100000 TPS im integrated message system
FTP protocol for Wireshark packet capture analysis
day30 js笔记 BOM和DOM 2021.09.24
Database Series: is there any way to seamlessly upgrade the business tables of the database
Simple understanding of ThreadLocal
Allez, Meta - Cosme, comme prévu, cette chaleur ne durera pas longtemps.
面试步骤的面试技巧
3. seat number
Excel import / export convenience tool class
Day39 prototype chain and page fireworks effect 2021.10.13
ProCAST finite element casting process simulation software
5. Sum of N numbers