MD5加密的工具类

package com.tools;
//对用户加密啊
import java.security.*;

public class MD5{
    public final static String code(String s) {
        char hexDigits[] = { ‘0‘, ‘1‘, ‘2‘, ‘3‘, ‘4‘, ‘5‘, ‘6‘, ‘7‘, ‘8‘, ‘9‘,‘a‘, ‘b‘, ‘c‘, ‘d‘, ‘e‘, ‘f‘ };
        try {
            byte[] strTemp = s.getBytes();
            MessageDigest mdTemp = MessageDigest.getInstance("MD5");
            mdTemp.update(strTemp);
            byte[] md = mdTemp.digest();
            int j = md.length;
            char str[] = new char[j * 2];
            int k = 0;
            for (int i = 0; i < j; i++) {
                byte byte0 = md[i];
                str[k++] = hexDigits[byte0 >>> 4 & 0xf];
                str[k++] = hexDigits[byte0 & 0xf];
            }
            return new String(str);
        } catch (Exception e) {
            return null;
        }
    }

public static void main(String[] args) {
        System.out.print(MD5.code("wubin123456"));
}

}
时间: 2024-10-16 13:18:53

MD5加密的工具类的相关文章

MD5加密Java工具类

原文:http://www.open-open.com/code/view/1421764946296 import java.security.MessageDigest; public class MD5 { //公盐 private static final String PUBLIC_SALT = "demo" ; //十六进制下数字到字符的映射数组 private final static String[] hexDigits = {"0", "

EncryptHelper加密对象-工具类

using System; using System.IO; using System.Security.Cryptography; using System.Text; using System.Web.Security; namespace Common.Utility { /// <summary> /// Author:Kt /// Date Created:2011-04-01 /// Description:加密对象-工具类 /// </summary> public

加密解密工具类(Java,DES)

一个Java版的DES加密工具类,可以用来进行网络数据传输加密,保存密码的时候进行加密. import java.security.Key; import java.security.spec.AlgorithmParameterSpec; import javax.crypto.Cipher; import javax.crypto.SecretKeyFactory; import javax.crypto.spec.DESKeySpec; import javax.crypto.spec.I

MD5加密解密帮助类

using System; using System.Security.Cryptography; using System.Text; namespace Maticsoft.DBUtility { /// <summary> /// DES加密/解密类. /// </summary> public class DESEncrypt { public DESEncrypt() { } #region ========加密======== /// <summary> /

AES加密解密工具类封装(AESUtil)

import org.springframework.util.Base64Utils; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; import java.util.logging.Level; import java.util.logging.Logger; import javax.crypto.Cipher; import javax.crypto.KeyGenerat

h5棋牌源码租用Java的MD5加密和解密类

理解MD5MD5的应用非常广泛h5棋牌源码租用(h5.hxforum.com)联系170618633533企鹅2952777280(http://yhgj8004.com)源码出售 房卡出售 后台出租联系方式只有企鹅.例如我们在unix中下载某种软件时,常常会看到一个扩展名为.md5的文件,内容大概是:MD5 (tanajiya.tar.gz) = 0ca175b9c0f726a831d895e269332461这就是tanajiya.tar.gz文件的数字签名.因此当我们得到这个文件后,使用工

本地加密解密工具类

import java.security.Key; import javax.crypto.Cipher; public class EncryptDecodeUtil { /** * 字符串默认键值 */ private static String strDefaultKey = "national"; /** * 加密工具 */ private Cipher encryptCipher = null; /** * 解密工具 */ private Cipher decryptCiph

自写AES加密解密工具类

此类主要用于加密与解密,采用128位ECB模式,PKCS5Padding填充补位. 可使用方法为加密返回二进制encryptBin(content, key).加密返回十六进制encryptHex(content, key).二进制内容解密decryptBin(content, key).十六进制内容解密decryptHex(content, key). content是需要加密的字符串,key是密钥,随意一个字符串. 1 package com.test; 2 3 import java.io

DES加密解密工具类

import java.security.InvalidKeyException; import java.security.Key; import java.security.NoSuchAlgorithmException; import javax.crypto.BadPaddingException; import javax.crypto.Cipher; import javax.crypto.IllegalBlockSizeException; import javax.crypto