Digital Summary:
A numeric digest, also known as a message digest, is a fixed-length value that uniquely corresponds to a message or text, which is a one-way
The hash function computes the message.
Summary generation Process: summary string -----> hash function -----> Summary
Features of the message digest:
1. No matter how long the message is entered, the length of the computed message digest is fixed. For example: The MD5 is 128 bits, and the SHA-1 is
160 bits;
2. In general, as long as the input message is different, the resulting summary message is not the same, the same input will inevitably produce the same summary message;
3. Because the message digest does not contain complete information for the original text, it can only forward the message digest and cannot recover the original message from the Digest
It is not even possible to find any messages related to the original information.
1.MD5:
Use of the Java-based MD5 algorithm:
650) this.width=650; "Src=" http://dl.iteye.com/upload/attachment/299017/c4164c4a-5925-385a-b7bd-438d34474085.jpg "alt=" C4164c4a-5925-385a-b7bd-438d34474085.jpg "/>
/**
* Implementation of MD5 encryption
*
* @param con
* Strings that need 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 (Abstract information length 160-bit one of the most secure hashing algorithms):
650) this.width=650; "Src=" http://dl.iteye.com/upload/attachment/299019/b8a0cd1d-26d1-3e31-bb9f-5d08e98ec704.jpg "alt=" B8a0cd1d-26d1-3e31-bb9f-5d08e98ec704.jpg "/>
/**
*sha Hashing Security algorithm
*
* @param con
* String to encrypt
* @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.16 Binary code:
/**
* 16 Binary 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 Binary decryption
*
* @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 Code:
/**
* Base64 Encoded
* @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 era of data, the security of information has become our concern, this issue of the blog wrote some basic encryption algorithm, hope to be useful to everyone. Other cryptographic algorithms I will gradually fill in the later writing.
This article is from the "in the Eyes of the Sun" blog, please be sure to keep this source http://wang963825.blog.51cto.com/8695943/1734883
Common cryptographic algorithms---digital abstracts