MD5 compression algorithm


package cn.com.test;
 /* incoming parameter: an array of bytes
  * Outgoing parameter: MD5 result character set of the byte array
 */
public class MD5 {

	public static String getMD5 (byte[] source){
		String s = null;
 		// used to convert bytes to hexadecimal representation of characters
		char hexDigits[] = {'0' ,'1', '2', '3', '4' ,'5' ,'6', '7','8','9','a','b','c','d','e','f'};
		
		try {
			java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5");
			md.update(source);
 			The result of the //MD5 calculation is a 128-bit long integer, which in bytes is 16 bytes
			byte tmp[] = md.digest();
 			// Each byte is represented in hexadecimal using two characters, so 32 characters are needed to represent it in hexadecimal
			char str[] = new char[16*2];
 			// indicates the position of the corresponding character in the conversion result
			int k = 0;
			for (int i= 0;i< 16;i++){
 				// Convert each byte of the MD5 to hexadecimal characters, starting with the first byte
 				//fetch the i-th byte
				byte byte0 = tmp[i];
				// Take the high of the byte4 Bitwise digital conversion,>>>  is a logical right shift, Shift the sign bits together to the right
				str[k++] = hexDigits[byte0 >>> 4 & 0xf];
 				//de-byte the lower 4 bits of the digital conversion
				str[k++] = hexDigits[byte0 & 0xf];				
			}
			s = new String(str);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return s;
	}
	public static void main(String[] args) {
		byte byarr[] = {'1','2','3','!','@','#'};
		System.out.println(MD5.getMD5(byarr));
	}
}

Recommended>>
1、Deep Learning and Neural Network Learning1 A Small Beginning
2、Twopoint distance
3、3python word cloud graph generation
4、Cloud Server MultiIP Scenarios in Practice
5、assert function

    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号