apatche组件的研究和使用

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

轻松一刻哦

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");
           }
   }

}


apatche组件的研究和使用


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论