做网站大概要多少钱,wordpress本地环境搭建,注册域名后如何建立网站,域名抢注哪个平台好数字摘要#xff1a;数字摘要也称为消息摘要#xff0c;它是一个唯一对应一个消息或文本的固定长度的值#xff0c;它是一个单向Hash函数对消息进行计算产生的。摘要生成的过程#xff1a;待摘要串----- Hash函数----- 摘要消息摘要的特点#xff1a;1.无论输入的… 数字摘要数字摘要也称为消息摘要它是一个唯一对应一个消息或文本的固定长度的值它是一个单向Hash函数对消息进行计算产生的。摘要生成的过程待摘要串----- Hash函数----- 摘要消息摘要的特点1.无论输入的消息多长计算出来的消息摘要的长度是固定的。例如MD5 的为128个比特位SHA-1的为160个比特位2.一般只要输入的消息不同对其产生的摘要消息也是不相同的相同的输入必然会产生相同的摘要消息3.由于消息摘要并不包含原文的完整信息因此只能进行正向的消息摘要而无法从摘要中恢复出原来的消息甚至根本不可能找到任何与原信息相关的消息。1.MD5基于java的MD5算法的使用/** * 实现MD5的加密 * * param con * 需要加密的字符串 * 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(摘要的信息长度160位 最安全的散列算法之一): /** *SHA 散列安全算法 * * param con * 待加密的字符串 * 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进制加密 * * 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编码 /** * base64 編碼 * param base64 * return * throws IOException */ private static byte[] base642byte(String base64) throws IOException { BASE64Decoder bs new BASE64Decoder(); return bs.decodeBuffer(base64); } /** * base64 解码 * param bytes * return */ private static String byte2base64(byte[] bytes) { BASE64Encoder bse new BASE64Encoder(); return bse.encode(bytes); } 随着数据化时代的到来信息的安全性越来越成为我们关注的问题本期博客写了一些基础的加密算法希望对大家有用。其他的加密算法我也会在后期的书写中逐渐补上。 转载于:https://blog.51cto.com/wang963825/1734883