commons-codec是Apache开源组织提供的用于摘要运算、编码解码的包。常见的编码解码工具Base64、MD5、Hex、SHA1、DES等。
System.out.println("===============base64======================");
Base64 base64 = new Base64();
String s = base64.encodeToString("测试22222222222".getBytes());
System.out.println(s);
String s1 = new String(base64.decode(s));
System.out.println(s1);
运算结果:
===============base64======================
5rWL6K+VMjIyMjIyMjIyMjI=
测试22222222222
System.out.println("===============MD5======================");
String result = DigestUtils.md5Hex("测试");
System.out.println(result);
远算结果:
===============MD5======================
db06c78d1e24cf708a14ce81c9b617ec
SHA运算和MD5是使用的同一个工具类。
- URLCodec
System.out.println("===============MD5======================");
URLCodec codec = new URLCodec();
String s = codec.encode("测试", "utf-8");
System.out.println(s);
String s1 = codec.decode(s, "utf-8");
System.out.println(s1);
运算结果:
===============MD5======================
%E6%B5%8B%E8%AF%95
测试