commons-codec-1.3.jar是jdk中一款用于编码运算的开源工具包,结构简单,调用方便,支持多种运算方式,有需要的程序猿们快来IT猫扑下载吧!

commons-codec.jar介绍

commons-codec是Apache开源组织提供的用于摘要运算、编码的包。

commons-codec.jar内容

Commons codec,是项目中用来处理常用的编码方法的工具类包,例如DES、SHA1、MD5、Base64,URL,Soundx等等。

不仅是编码,也可用于解码。

在该包中主要分为四类加密:BinaryEncoders、DigestEncoders、LanguageEncoders、NetworkEncoders。

commons codec1.3.jar

commons-codec.jar运算示例

可逆算法

常规加密解密算法:BASE64

加密

String str= "abc"; // abc为要加密的字符串

byte[] b = Base64.encodeBase64(str.getBytes(), true);

System.out.println(new String(b));

解密

String str = "YWJj"; // YWJj为要解密的字符串

byte[] b = Base64.decodeBase64(str.getBytes());

System.out.println(new String(b));

不可逆算法

1、MD5

String str = "abc";

DigestUtils.md5Hex(str);

附.net生成MD5的方法,生成内容跟java一致:

String str = "abc";

FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5");

2、SHA1

String str = "abc";

DigestUtils.shaHex(str);

附.net生成SHA1的方式,生成内容跟java一致:

String str = "abc";

FormsAuthentication.HashPasswordForStoringInConfigFile(str, "SHA1");

下载地址

远程下载