摘要加密算法
(1)?????? 什么是摘要加密?
摘要加密是一种不需要密钥的加密算法,明文进行加密之后生成唯一的密文并且无法破解,觉有不可逆性、唯一性
(2)?????? 编程import java.security.MessageDigest;import java.security.NoSuchAlgorithmException;import sun.misc.BASE64Encoder;public class MessageDigestUtil {private static void test1() throws NoSuchAlgorithmException{MessageDigest md = MessageDigest.getInstance("md5");String str = "i love you ";byte[] buf = md.digest(str.getBytes());//字节数组不方便使用所以一般转换为字符串BASE64Encoder encoder = new BASE64Encoder();String str2 = encoder.encode(buf);System.out.println(str2);}//编写成工具类public static String encrypt(String origStr) throws NoSuchAlgorithmException{MessageDigest md = MessageDigest.getInstance("md5");byte[] buf = md.digest(origStr.getBytes());//字节数组不方便使用所以一般转换为字符串BASE64Encoder encoder = new BASE64Encoder();String str = encoder.encode(buf);return str;}public static void main(String[] args) {try {System.out.println(encrypt("i love you "));} catch (NoSuchAlgorithmException e) {e.printStackTrace();}try {test1();} catch (NoSuchAlgorithmException e) {e.printStackTrace();}}}
?
?