In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
Digital Summary:
A digital digest, also known as a message digest, is a value of fixed length that uniquely corresponds to a message or text. It is an one-way message.
The Hash function calculates the message.
The process of generating a summary: string to be summarized-> Hash function-> summary
Characteristics of message digest:
1. The length of the calculated message digest is fixed no matter how long the message is entered. For example: 128bits for MD5 and 128bits for SHA-1
160 bits
two。 Generally speaking, as long as the input message is different, the summary message generated by it is also different, and the same input will inevitably produce the same summary message.
3. Since the message digest does not contain the complete information of the original text, only a positive message digest can be performed, and the original message cannot be recovered from the digest.
It is even impossible to find any information related to the original information.
1.MD5:
The use of MD5 algorithm based on java:
/ * *
* implement MD5 encryption
*
* @ param con
* string that needs to be encrypted
* @ return
* @ throws Exception
, /
Private static byte [] testMD5 (String con) throws Exception {
MessageDigest md5 = MessageDigest.getInstance ("MD5")
Byte [] bytes = md5.digest (con.getBytes ("utf-8"))
Return bytes
}
2.SHA (one of the safest hashing algorithms for a summary with a message length of 160 bits):
/ * *
* SHA hash security algorithm
*
* @ param con
* string to be encrypted
* @ return
* @ throws Exception
, /
Private static byte [] tstSHA1 (String con) throws Exception {
MessageDigest sha = MessageDigest.getInstance ("SHA-1")
Byte [] bytes = sha.digest (con.getBytes ("utf-8"))
Return bytes
}
3. Hexadecimal coding:
/ * *
* hexadecimal encryption
*
* @ param bytes
* @ return
, /
Private static String bytes2hex (byte [] bytes) {
StringBuilder hex = new StringBuilder ()
For (int I = 0; I
< bytes.length; i++) { byte b = bytes[i]; boolean negtive = false; if (b < 0) { negtive = true; } int inte = Math.abs(b); if (negtive) inte = inte | 0x80; String temp = Integer.toHexString(inte & 0xFF); if (temp.length() == 1) { hex.append("0"); } hex.append(temp.toLowerCase()); } return hex.toString(); } /** * 16进制解密 * * @param hex * @return */ private static byte[] hex2bytes(String hex) { byte[] bytes = new byte[hex.length() / 2]; for (int i = 0; i < hex.length(); i = i + 2) { String subStr = hex.substring(i, i + 2); boolean negative = false; int inte = Integer.parseInt(subStr, 16); if (inte >127) {
Negative = true
}
If (inte = = 128) {
Inte =-128,
} else if (negative) {
Inte = 0-(inte & 0x7F)
}
Byte b = (byte) inte
Bytes [I / 2] = b
}
Return bytes
}
4.Base64 coding:
/ * *
* base64 coding
* @ param base64
* @ return
* @ throws IOException
, /
Private static byte [] base642byte (String base64) throws IOException {
BASE64Decoder bs = new BASE64Decoder ()
Return bs.decodeBuffer (base64)
}
/ * *
* base64 decoding
* @ param bytes
* @ return
, /
Private static String byte2base64 (byte [] bytes) {
BASE64Encoder bse = new BASE64Encoder ()
Return bse.encode (bytes)
}
With the advent of the digital era, the security of information has increasingly become our concern. This blog has written some basic encryption algorithms, hoping to be useful to you. I will also gradually fill in other encryption algorithms in later writing.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.