当前位置:网站首页>Sha256 encryption tool class
Sha256 encryption tool class
2022-06-28 12:11:00 【A cup of bitter mustard】
public class SHA256Util {
/**
* use java Native summary implementation SHA256 encryption
*
* @param str Message before encryption
* @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[] To 16 Base number
*
* @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();
}
}
边栏推荐
- Allez, Meta - Cosme, comme prévu, cette chaleur ne durera pas longtemps.
- Convert black mask picture to color annotation file
- [sciter]: use of sciter FS module scanning file API and its details
- day28 严格模式、字符串 js 2021.09.22
- Come on, yuanuniverse. Sure enough, the heat won't pass for a while
- day25 js中的预解析、递归函数、事件 2021.09.16
- Research on personalized product search
- 期货开户有门槛吗,如何网上安全的开通期货账户
- Join hands with cigent: group alliance introduces advanced network security protection features for SSD master firmware
- 【C语言】二叉树的实现及三种遍历
猜你喜欢

Leetcode 705. 设计哈希集合

SEO优化的许多好处是与流量有直接关系

Django -- MySQL database reflects the mapping data model to models

Cannot redeclare block range variables

Is it feasible to be a programmer at the age of 26?

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

Data analysis learning notes

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

【C语言】如何产生正态分布或高斯分布随机数

Chendanqi, Fang Fei, guquanquan and Li Bo won the prize, and the list of Sloan research award in 2022 was released
随机推荐
day24 js笔记 2021.09.15
Leetcode 48. 旋转图像(可以,已解决)
MapReduce项目案例1
Excel import / export convenience tool class
【C语言】随机数文件对其进行三种排序方法
AcWing 610. Salary and bonus (implemented in C language)
SHA256加密工具类
Interview skills for interview steps
day39 原型鏈及頁面烟花效果 2021.10.13
The development and principle of the metacosmic system
【JS】斐波那契数列实现(递归与循环)
Apache2 configuration denies access to the directory, but can access the settings of the files inside
【C语言】如何产生正态分布或高斯分布随机数
Android应用安全之JNI混淆
Day34 JS notes regular expression 2021.09.29
4. maximum continuity factor
开源项目维权成功案例: spug 开源运维平台成功维权
Contract quantitative trading system development | contract quantitative app development (ready-made cases)
Graphics view framework for QT learning (to realize startup animation)
fatal: unsafe repository (‘/home/anji/gopath/src/gateway‘ is owned by someone else)