apatche组件的研究和使用

本节讲述加密算法和加密算法的使用研究
如果有疑问请看源代码:

轻松一刻哦

o(∩_∩)o...哈哈
徘徊在牛A和牛B之间的人
o(∩_∩)o...哈哈


package cn.com.huawei.opensource.common.codecs;


import java.util.logging.Logger;

import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.language.Metaphone;
import org.apache.commons.codec.language.RefinedSoundex;
import org.apache.commons.codec.language.Soundex;
import org.apache.commons.codec.digest.DigestUtils;

/**
*Commons-codec组件设置各种编码是算法的信息
* @author bailonggang
* 2009-2-8
* 下午03:58:14
*/
public class CodeCUtil {

private static Logger logger=Logger.getLogger(CodeCUtil.class.getName());
/**
* MD5加密的过程的应用
* @param crbyte
* @return
*/
public static String encodeMD5(String crbyte)
{
byte[] bytes=crbyte.getBytes();

return DigestUtils.md5Hex(bytes);

}
/**
* MD5加密的过程的应用
* @param crbyte
* @return
*/
public static String encodeSHA1(String crbyte)
{
byte[] bytes=crbyte.getBytes();
return DigestUtils.shaHex(bytes);

}
/**
* 字符串的解码过程
* @param enbytes
* @return
*/
public static Object decodeBase64(String enbytes)
{
Base64 base64 = new Base64();
Object obj=null;
try {
obj = base64.decode(enbytes);
} catch (DecoderException e) {
logger.info("base64 decode ["+enbytes+"] error:"+e.getMessage());
}
return obj;
}
/**
* base64编码的过程的信息
* @param crbty
* @return
*/
public static String encodeBase64(String crbty)
{
Base64 base64 = new Base64();
byte[] enbytes =base64.encode(crbty.getBytes());
return new String(enbytes);
}
/**
* 十六进制加密的过程
* @param enbyte
* @return
* @throws DecoderException
*/
public static String encodeHex(String enbyte) throws DecoderException
{
char[] enbytes = Hex.encodeHex(enbyte.getBytes());
return new String(enbytes);
}
/**
* 十六进制解密的过程
* @param enbytes
* @return
* @throws DecoderException
*/
public static String decodeHex(String enbytes) throws DecoderException
{
byte[] bytes=Hex.decodeHex(enbytes.toCharArray());
return new String(bytes);
}
/**
* Metaphone 建立出相同的key给发音相似的单字, 比 Soundex 还要准确, 但是 Metaphone
* 没有固定长度, Soundex 则是固定第一个英文字加上3个数字. 这通常是用在类似音比对,
* 也可以用在 MP3 的软件开发.
*
*/
public static void languageEncoding()
{
Metaphone metaphone = new Metaphone();
RefinedSoundex refinedSoundex = new RefinedSoundex();
Soundex soundex = new Soundex();
for (int i = 0; i < 2; i++) {
String str = (i == 0) ? "resume" : "resin";
String mString = null;
String rString = null;
String sString = null;
try {
mString = metaphone.encode(str);
rString = refinedSoundex.encode(str);
sString = soundex.encode(str);
} catch (Exception ex){
;
}
System.out.println("Original:" + str);
System.out.println("Metaphone:" + mString);
System.out.println("RefinedSoundex:" + rString);
System.out.println("Soundex:" + sString + "\n");
}
}

}


:D
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值