MD5加密算法

package com.bao.tools.encryption;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import org.junit.Test;

import sun.misc.BASE64Encoder;

/**
 * @title md5加密算法
 * @author Administrator
 * @date 2015-7-16
 */
public class CMD5 {
    /*
     * MD5加密算法
     */
    public static String setEncrypted(String value) throws NoSuchAlgorithmException{
        if(value==null)return null;
        MessageDigest digest = MessageDigest.getInstance("MD5");
        BASE64Encoder encoder = new BASE64Encoder();
        return encoder.encode(digest.digest(value.getBytes()));
    }
    
    /*
     * 测试
     */
    @Test
    public void test() throws NoSuchAlgorithmException{
        String name = "hh52好 !";
        
        System.out.println("加密前:"+name);
        System.out.println("加密 :"+CMD5.setEncrypted(name));
    }
}

运行结果

注明:根据网上叙述,MD5使用不可逆变换字符串算法,加上其中还可以再次加密,这样安全系数是比较高的,所有在个人技术无法实现解密方案 。

posted @ 2015-07-16 11:54  rickbao  阅读(173)  评论(0编辑  收藏  举报