private static final String strType = "SHA-256";
/***
* 字符串 SHA 加密**
*
@param strSourceText
* @return
*/
public static byte[] SHA(final String strText) {
// 是否是有效字符串
if (strText != null && strText.length() > 0) {
try {
// SHA 加密开始
// 创建加密对象 并传入加密类型
MessageDigest messageDigest = MessageDigest.getInstance(strType);
// 传入要加密的字符串
messageDigest.update(strText.getBytes());
// 得到 byte 类型结果
return messageDigest.digest();
} catch (NoSuchAlgorithmException e) {
return null;
}
}else{
return null;
}
}
Java SHA256加密
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.