.Net JAVA JS 加密(三方互通)

JAVA加密类:

import java.io.UnsupportedEncodingException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.HashMap;
import java.util.Map;

import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.KeyGenerator;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;


public class EnUtil {


	private final static String AES_CIPHER = "AES/CBC/NoPadding";
	private final static String AES_SECRET = "AES";

	public static void main(String[] args) {

		/*String pwdKey = "225E8C70688FD76EC5C01A392302320A";
		String pwd = "440196";

		
		
		System.out.println("生成密文 : " + (encrypt(pwd, pwdKey)));
		String con = "25F558AD2366AECCCB0E5FC192514737";
		System.out.println("解密 : " + decrypt(con, pwdKey));*/
		
		
		System.out.println("生成密文 : " + md5("Hello"));
	}

	public static byte[] genKey() {
		byte[] result = null;
		try {
			// KeyGenerator提供对称密钥生成器的功能,支持各种算法
			KeyGenerator keygen = KeyGenerator.getInstance("AES");
			keygen.init(128, new SecureRandom());
			// SecretKey负责保存对称密钥
			SecretKey deskey = keygen.generateKey();
			result = deskey.getEncoded();
		} catch (NoSuchAlgorithmException e) {
			//log.warn("[AES密钥生成]系统不支持AES算法", e);
		}
		return result;
	}

	public static byte[] genMD5Key() {
		byte[] result = null;
		try {
			// KeyGenerator提供对称密钥生成器的功能,支持各种算法
			KeyGenerator keygen = KeyGenerator.getInstance("AES");
			keygen.init(128, new SecureRandom());
			// SecretKey负责保存对称密钥
			SecretKey deskey = keygen.generateKey();
			result = deskey.getEncoded();
		} catch (NoSuchAlgorithmException e) {
			//log.warn("[AES密钥生成]系统不支持AES算法", e);
		}
		return result;
	}

	private static final char[] h = "0123456789ABCDEF".toCharArray();

	private static Map<Character, Integer> hs = new HashMap<Character, Integer>();
	static {
		for (int i = 'A'; i <= 'F'; i++) {
			hs.put(((char) i), i - 'A' + 10);
		}
		for (int i = 'a'; i <= 'f'; i++) {
			hs.put(((char) i), i - 'a' + 10);
		}
		for (int i = '0'; i <= '9'; i++) {
			hs.put(((char) i), i - '0');
		}
	}

	/**
	 * 十六进制字符串转二进制数据流
	 * 
	 * @param hex
	 * @return
	 */
	public static byte[] h2b(String hex) {

		byte[] bs = new byte[hex.length() / 2];
		int i = 0;
		char[] s = hex.toCharArray();
		for (int j = 0; j < s.length;) {
			bs[i++] = (byte) ((hs.get(s[j++]) << 4) | hs.get(s[j++]));
		}
		return bs;
	}

	/**
	 * 二进制数据流转十六进制字符串
	 * 
	 * @param bytes
	 * @return
	 */
	public static String h2s(byte[] bytes) {

		StringBuilder s = new StringBuilder();
		for (byte b : bytes) {
			s.append(h[(b >> 4) & 0xF]);
			s.append(h[b & 0xF]);
		}

		return s.toString();
	}

	/**
	 * AES加密
	 * 
	 * @param data
	 *            明文
	 * @param key
	 *            密钥
	 * @return 密文
	 */
	public static String encrypt(String data, String key) {
		//System.out.println("[AES加密]加密前--明文 : " + data + "; 加密密钥 : " + key);

		int len = data.length();
		StringBuilder d = new StringBuilder();
		d.append(leftFill(len, 2, "0"));
		d.append(rightFill(data, 14, "F"));
		String tmp = null;
		String result = h2s(encrypt((tmp = d.toString()).getBytes(), h2b(key)));
		//System.out.println("[AES加密]加密后--明文 : " + data + "(" + tmp + "); 加密密钥 : " + key+ "; 加密密文 : " + result);
		return result;
	}

	/**
	 * AES解密
	 * 
	 * @param data
	 *            密文
	 * @param key
	 *            密钥
	 * @return 明文
	 */
	public static String decrypt(String data, String key) {
		//System.out.println("[AES解密]解密前--密文 : " + data + "; 解密密钥 : " + key);
		byte[] bytes = decrypt(h2b(data), h2b(key));
		//System.out.println("[AES解密]解密结束 : " + (bytes == null ? "null" : h2s(bytes)));
		String result = bytes == null ? null : new String(bytes);
		if (result != null && result.length() > 1) {
			int len = Integer.valueOf(result.substring(0, 2));
			if (len + 2 <= result.length())
				result = result.substring(2, len + 2);
		}
		//System.out.println("[AES解密]解密后--密文 : " + data + "; 解密密钥 : " + key + "; 解密明文 : "+ result);
		return result;
	}

	/**
	 * AES加密方法
	 * 
	 * @param data
	 *            待加密明文
	 * @param key
	 *            加密密钥
	 * @return
	 */
	public static byte[] encrypt(byte[] data, byte[] key) {

		byte[] encryptedData = null;
		try {
			Cipher cipher = Cipher.getInstance(AES_CIPHER);// 创建密码器
			IvParameterSpec iv = new IvParameterSpec(key);
			SecretKeySpec sp = new SecretKeySpec(createKey(key), AES_SECRET);

			cipher.init(Cipher.ENCRYPT_MODE, sp, iv);// 初始化
			// 执行加密操作
			encryptedData = cipher.doFinal(data);
		} catch (NoSuchAlgorithmException e) {
			//log.warn("[AES加密]系统不支持AES算法", e);
		} catch (InvalidKeyException e) {
			//log.warn("[AES加密]非法的密钥格式", e);
		} catch (NoSuchPaddingException e) {
			//log.warn("[AES加密]加密算法运算出错", e);
		} catch (IllegalBlockSizeException e) {
			//log.warn("[AES加密]加密数据块大小不正确", e);
		} catch (BadPaddingException e) {
			//log.warn("[AES加密]错误的加密数据封装", e);
		} catch (InvalidAlgorithmParameterException e) {
			//log.warn("[AES加密]错误的加密算法参数", e);
		}
		return encryptedData;
	}

	/**
	 * AES解密算法
	 * 
	 * @param data
	 *            待解密密文
	 * @param key
	 *            解密密钥
	 * @return
	 */
	public static byte[] decrypt(byte[] data, byte[] key) {
		byte[] decryptedData = null;

		try {
			Cipher cipher = Cipher.getInstance(AES_CIPHER);// 创建密码器
			IvParameterSpec iv = new IvParameterSpec(key);
			SecretKeySpec sp = new SecretKeySpec(createKey(key), AES_SECRET);

			cipher.init(Cipher.DECRYPT_MODE, sp,iv);// 初始化

			// 执行加密操作
			decryptedData = cipher.doFinal(data);

		} catch (NoSuchAlgorithmException e) {
			//log.warn("[AES解密]系统不支持AES算法", e);
		} catch (InvalidKeyException e) {
			//log.warn("[AES解密]解法的密钥格式", e);
		} catch (NoSuchPaddingException e) {
			//log.warn("[AES解密]解密算法运算出错", e);
		} catch (IllegalBlockSizeException e) {
			//log.warn("[AES解密]解密数据块大小不正确", e);
		} catch (BadPaddingException e) {
			//log.warn("[AES解密]错误的解密数据封装", e);
		} catch (InvalidAlgorithmParameterException e) {
			//log.warn("[AES加密]错误的解密算法参数", e);
		}

		return decryptedData;
	}

	public static byte[] createKey(byte[] key) {
		 return key;
//		String algorithmName = "";
//		try {
//			algorithmName = "AES";
//			KeyGenerator kgen = KeyGenerator.getInstance(algorithmName);
//			algorithmName = "SHA1PRNG";
//			SecureRandom secureRandom = SecureRandom.getInstance(algorithmName);
//			secureRandom.setSeed(key);
//			kgen.init(128, secureRandom);
//			SecretKey secretKey = kgen.generateKey();
//			return secretKey.getEncoded();
//		} catch (NoSuchAlgorithmException e) {
//			log.warn("[密钥生成]系统不支持此算法", e);
//		}
//		return null;
	}

	/**
	 * MD5 校验
	 * 
	 * @param data
	 * @return
	 */
	public static String md5(String data) {

		String result = null;
		try {
			result = h2s(md5(data.getBytes("UTF-8")));
		} catch (UnsupportedEncodingException e) {
			//log.warn("[MD5加密]程序不支持 UTF-8 编码");
		}
		//System.out.println("[MD5加密]校验结果 : " + result + "; 校验内容 : " + data);
		return result;
	}

	/**
	 * MD5加密
	 * 
	 * @param data
	 * @return
	 */
	public static byte[] md5(byte[] data) {

		byte[] result = null;
		try {
			MessageDigest messageDigest = MessageDigest.getInstance("MD5");
			messageDigest.reset();
			messageDigest.update(data);
			result = messageDigest.digest();
		} catch (NoSuchAlgorithmException e) {
			//log.warn("[MD5加密]不支持MD5算法", e);
		}

		return result;
	}

	/**
	 * 左补充
	 * 
	 * @param obj
	 * @param len
	 * @param fill
	 * @return
	 */
	public static String leftFill(Object obj, int len, String fill) {

		if (obj == null)
			return null;
		String src = String.valueOf(obj);
		StringBuilder s = new StringBuilder();
		for (int l = src.length(); l < len; l++) {
			s.append(fill);
		}
		s.append(src);
		return s.toString();
	}

	/**
	 * 右补充
	 * 
	 * @param obj
	 * @param len
	 * @param fill
	 * @return
	 */
	public static String rightFill(Object obj, int len, String fill) {

		if (obj == null)
			return null;
		String src = String.valueOf(obj);
		StringBuilder s = new StringBuilder();
		s.append(src);
		for (int l = src.length(); l < len; l++) {
			s.append(fill);
		}
		return s.toString();
	}

}

MD5加密得到结果:                    生成密文 : 8B1A9953C4611296A827ABF8C47804D7



.NET加密类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Security.Cryptography;
using System.IO;

namespace ConsoleApplication5
{
    public class AESUtility
    {
        private static char[] h = "0123456789ABCDEF".ToCharArray();
        private static Dictionary<char, int> hs = new Dictionary<char, int>();
        static AESUtility()
        {
            for (int i = 'A'; i <= 'F'; i++)
            {
                hs.Add(((char)i), i - 'A' + 10);
            }
            for (int i = 'a'; i <= 'f'; i++)
            {
                hs.Add(((char)i), i - 'a' + 10);
            }
            for (int i = '0'; i <= '9'; i++)
            {
                hs.Add(((char)i), i - '0');
            }
        }
        public static string MD5(string input)
        {
            MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider();
            // Convert the input string to a byte array and compute the hash.  
            char[] temp = input.ToCharArray();
            byte[] buf = new byte[temp.Length];
            for (int i = 0; i < temp.Length; i++)
            {
                buf[i] = (byte)temp[i];
            }
            byte[] data = md5Hasher.ComputeHash(buf);
            // Create a new Stringbuilder to collect the bytes  
            // and create a string.  
            StringBuilder sBuilder = new StringBuilder();
            // Loop through each byte of the hashed data   
            // and format each one as a hexadecimal string.  
            for (int i = 0; i < data.Length; i++)
            {
                sBuilder.Append(data[i].ToString("x2"));
            }
            // Return the hexadecimal string.  
            return sBuilder.ToString().ToUpper();
        }  
        /// <summary>
        /// AES加密(互通JAVA)
        /// </summary>
        /// <param name="data">明文</param>
        /// <param name="key">密钥</param>
        /// <returns>密文</returns>
        public static string Encrypt(string data, string key)
        {
            string result = string.Empty;
            int len = data.Length;
            StringBuilder d = new StringBuilder();
            d.Append(leftFill(len, 2, "0"));
            d.Append(rightFill(data, 14, "F"));

            result = h2s(Encrypt(Encoding.UTF8.GetBytes(d.ToString()), h2b(key)));

            return result;
        }
        /// <summary>
        /// AES解密(互通JAVA)
        /// </summary>
        /// <param name="data"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string Decrypt(string data, string key)
        {
            byte[] bytes = Decrypt(h2b(data), h2b(key));
            string result = UTF8Encoding.UTF8.GetString(bytes);
            if (result != null && result.Length > 1)
            {
                int len = int.Parse(result.Substring(0, 2));
                if (len + 2 <= result.Length)
                    result = result.Substring(2, len + 2 - 2);
            }
            return result;
        }
        /// <summary>
        /// AES解密(互通JAVA)
        /// </summary>
        /// <param name="data"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static byte[] Decrypt(byte[] data, byte[] key)
        {
            byte[] keyArray = key;
            byte[] ivArray = key;
            byte[] toEncryptArray = data;

            RijndaelManaged rDel = new RijndaelManaged();
            rDel.Key = keyArray;
            rDel.IV = ivArray;
            rDel.Mode = CipherMode.CBC;
            rDel.Padding = PaddingMode.Zeros;

            ICryptoTransform cTransform = rDel.CreateDecryptor();
            byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
            return resultArray;
        }
        /// <summary>
        /// AES加密(互通JAVA)
        /// </summary>
        /// <param name="pToEncrypt"></param>
        /// <returns></returns>
        public static byte[] Encrypt(byte[] data, byte[] key)
        {
            byte[] keyArray = key;
            byte[] ivArray = key;
            byte[] toEncryptArray = data;
            RijndaelManaged rDel = new RijndaelManaged();
            rDel.Key = keyArray;
            rDel.IV = ivArray;
            rDel.Mode = CipherMode.CBC;
            rDel.Padding = PaddingMode.Zeros;
            ICryptoTransform cTransform = rDel.CreateEncryptor();
            byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);

            return resultArray;

        }
        /// <summary>
        /// 二进制数据流转十六进制字符串
        /// </summary>
        /// <param name="bytes"></param>
        /// <returns></returns>
        public static String h2s(byte[] bytes)
        {

            StringBuilder s = new StringBuilder();
            foreach (byte b in bytes)
            {
                s.Append(h[(b >> 4) & 0xF]);
                s.Append(h[b & 0xF]);
            }
            return s.ToString();
        }
        /// <summary>
        /// 十六进制字符串转二进制数据流
        /// </summary>
        /// <param name="hex"></param>
        /// <returns></returns>
        public static byte[] h2b(String hex)
        {
            byte[] bs = new byte[hex.Length / 2];
            int i = 0;
            char[] s = hex.ToCharArray();
            for (int j = 0; j < s.Length; )
            {
                bs[i++] = (byte)((hs[s[j++]] << 4) | hs[s[j++]]);
            }
            return bs;
        }
        /// <summary>
        /// 左补充
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="len"></param>
        /// <param name="fill"></param>
        /// <returns></returns>
        public static string leftFill(object obj, int len, string fill)
        {

            if (obj == null)
                return null;
            string src = obj.ToString();
            StringBuilder s = new StringBuilder();
            for (int l = src.Length; l < len; l++)
            {
                s.Append(fill);
            }
            s.Append(src);
            return s.ToString();
        }
        /// <summary>
        /// 右补充
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="len"></param>
        /// <param name="fill"></param>
        /// <returns></returns>
        public static string rightFill(object obj, int len, string fill)
        {

            if (obj == null)
                return null;
            string src = obj.ToString();
            StringBuilder s = new StringBuilder();
            s.Append(src);
            for (int l = src.Length; l < len; l++)
            {
                s.Append(fill);
            }
            return s.ToString();
        }
    }
}


using ConsoleApplication5;
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;

namespace ConsoleApp_PreventFileTampering
{
    class Program
    {
        static void Main(string[] args)
        {
            //string pwdKey = "225E8C70688FD76EC5C01A392302320A";
            //string pwd = "440196";
            //Console.WriteLine(AESUtility.Encrypt(pwd, pwdKey));
            //string con = "25F558AD2366AECCCB0E5FC192514737";
            //Console.WriteLine(AESUtility.Decrypt(con, pwdKey));  

            Console.WriteLine(AESUtility.MD5("Hello"));
        }

        

    }
}


MD5加密得到结果:                                      8B1A9953C4611296A827ABF8C47804D7


JS加密类

jQuery.md5.js

	/**
	 * jQuery MD5 hash algorithm function
	 * 
	 * 	<code>
	 * 		Calculate the md5 hash of a String 
	 * 		String $.md5 ( String str )
	 * 	</code>
	 * 
	 * Calculates the MD5 hash of str using the 禄 RSA Data Security, Inc. MD5 Message-Digest Algorithm, and returns that hash. 
	 * MD5 (Message-Digest algorithm 5) is a widely-used cryptographic hash function with a 128-bit hash value. MD5 has been employed in a wide variety of security applications, and is also commonly used to check the integrity of data. The generated hash is also non-reversable. Data cannot be retrieved from the message digest, the digest uniquely identifies the data.
	 * MD5 was developed by Professor Ronald L. Rivest in 1994. Its 128 bit (16 byte) message digest makes it a faster implementation than SHA-1.
	 * This script is used to process a variable length message into a fixed-length output of 128 bits using the MD5 algorithm. It is fully compatible with UTF-8 encoding. It is very useful when u want to transfer encrypted passwords over the internet. If you plan using UTF-8 encoding in your project don't forget to set the page encoding to UTF-8 (Content-Type meta tag). 
	 * This function orginally get from the WebToolkit and rewrite for using as the jQuery plugin.
	 * 
	 * Example
	 * 	Code
	 * 		<code>
	 * 			$.md5("I'm Persian."); 
	 * 		</code>
	 * 	Result
	 * 		<code>
	 * 			"b8c901d0f02223f9761016cfff9d68df"
	 * 		</code>
	 * 
	 * @alias Muhammad Hussein Fattahizadeh < muhammad [AT] semnanweb [DOT] com >
	 * @link http://www.semnanweb.com/jquery-plugin/md5.html
	 * @see http://www.webtoolkit.info/
	 * @license http://www.gnu.org/licenses/gpl.html [GNU General Public License]
	 * @param {jQuery} {md5:function(string))
	 * @return string
	 */
	(function($){
		var rotateLeft = function(lValue, iShiftBits) {
			return (lValue << iShiftBits) | (lValue >>> (32 - iShiftBits));
		}
		var addUnsigned = function(lX, lY) {
			var lX4, lY4, lX8, lY8, lResult;
			lX8 = (lX & 0x80000000);
			lY8 = (lY & 0x80000000);
			lX4 = (lX & 0x40000000);
			lY4 = (lY & 0x40000000);
			lResult = (lX & 0x3FFFFFFF) + (lY & 0x3FFFFFFF);
			if (lX4 & lY4) return (lResult ^ 0x80000000 ^ lX8 ^ lY8);
			if (lX4 | lY4) {
				if (lResult & 0x40000000) return (lResult ^ 0xC0000000 ^ lX8 ^ lY8);
				else return (lResult ^ 0x40000000 ^ lX8 ^ lY8);
			} else {
				return (lResult ^ lX8 ^ lY8);
			}
		}
		var F = function(x, y, z) {
			return (x & y) | ((~ x) & z);
		}
		var G = function(x, y, z) {
			return (x & z) | (y & (~ z));
		}
		var H = function(x, y, z) {
			return (x ^ y ^ z);
		}
		var I = function(x, y, z) {
			return (y ^ (x | (~ z)));
		}
		var FF = function(a, b, c, d, x, s, ac) {
			a = addUnsigned(a, addUnsigned(addUnsigned(F(b, c, d), x), ac));
			return addUnsigned(rotateLeft(a, s), b);
		};
		var GG = function(a, b, c, d, x, s, ac) {
			a = addUnsigned(a, addUnsigned(addUnsigned(G(b, c, d), x), ac));
			return addUnsigned(rotateLeft(a, s), b);
		};
		var HH = function(a, b, c, d, x, s, ac) {
			a = addUnsigned(a, addUnsigned(addUnsigned(H(b, c, d), x), ac));
			return addUnsigned(rotateLeft(a, s), b);
		};
		var II = function(a, b, c, d, x, s, ac) {
			a = addUnsigned(a, addUnsigned(addUnsigned(I(b, c, d), x), ac));
			return addUnsigned(rotateLeft(a, s), b);
		};
		var convertToWordArray = function(string) {
			var lWordCount;
			var lMessageLength = string.length;
			var lNumberOfWordsTempOne = lMessageLength + 8;
			var lNumberOfWordsTempTwo = (lNumberOfWordsTempOne - (lNumberOfWordsTempOne % 64)) / 64;
			var lNumberOfWords = (lNumberOfWordsTempTwo + 1) * 16;
			var lWordArray = Array(lNumberOfWords - 1);
			var lBytePosition = 0;
			var lByteCount = 0;
			while (lByteCount < lMessageLength) {
				lWordCount = (lByteCount - (lByteCount % 4)) / 4;
				lBytePosition = (lByteCount % 4) * 8;
				lWordArray[lWordCount] = (lWordArray[lWordCount] | (string.charCodeAt(lByteCount) << lBytePosition));
				lByteCount++;
			}
			lWordCount = (lByteCount - (lByteCount % 4)) / 4;
			lBytePosition = (lByteCount % 4) * 8;
			lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80 << lBytePosition);
			lWordArray[lNumberOfWords - 2] = lMessageLength << 3;
			lWordArray[lNumberOfWords - 1] = lMessageLength >>> 29;
			return lWordArray;
		};
		var wordToHex = function(lValue) {
			var WordToHexValue = "", WordToHexValueTemp = "", lByte, lCount;
			for (lCount = 0; lCount <= 3; lCount++) {
				lByte = (lValue >>> (lCount * 8)) & 255;
				WordToHexValueTemp = "0" + lByte.toString(16);
				WordToHexValue = WordToHexValue + WordToHexValueTemp.substr(WordToHexValueTemp.length - 2, 2);
			}
			return WordToHexValue;
		};
		var uTF8Encode = function(string) {
			string = string.replace(/\x0d\x0a/g, "\x0a");
			var output = "";
			for (var n = 0; n < string.length; n++) {
				var c = string.charCodeAt(n);
				if (c < 128) {
					output += String.fromCharCode(c);
				} else if ((c > 127) && (c < 2048)) {
					output += String.fromCharCode((c >> 6) | 192);
					output += String.fromCharCode((c & 63) | 128);
				} else {
					output += String.fromCharCode((c >> 12) | 224);
					output += String.fromCharCode(((c >> 6) & 63) | 128);
					output += String.fromCharCode((c & 63) | 128);
				}
			}
			return output;
		};
		$.extend({
			md5: function(string) {
				var x = Array();
				var k, AA, BB, CC, DD, a, b, c, d;
				var S11=7, S12=12, S13=17, S14=22;
				var S21=5, S22=9 , S23=14, S24=20;
				var S31=4, S32=11, S33=16, S34=23;
				var S41=6, S42=10, S43=15, S44=21;
				string = uTF8Encode(string);
				x = convertToWordArray(string);
				a = 0x67452301; b = 0xEFCDAB89; c = 0x98BADCFE; d = 0x10325476;
				for (k = 0; k < x.length; k += 16) {
					AA = a; BB = b; CC = c; DD = d;
					a = FF(a, b, c, d, x[k+0],  S11, 0xD76AA478);
					d = FF(d, a, b, c, x[k+1],  S12, 0xE8C7B756);
					c = FF(c, d, a, b, x[k+2],  S13, 0x242070DB);
					b = FF(b, c, d, a, x[k+3],  S14, 0xC1BDCEEE);
					a = FF(a, b, c, d, x[k+4],  S11, 0xF57C0FAF);
					d = FF(d, a, b, c, x[k+5],  S12, 0x4787C62A);
					c = FF(c, d, a, b, x[k+6],  S13, 0xA8304613);
					b = FF(b, c, d, a, x[k+7],  S14, 0xFD469501);
					a = FF(a, b, c, d, x[k+8],  S11, 0x698098D8);
					d = FF(d, a, b, c, x[k+9],  S12, 0x8B44F7AF);
					c = FF(c, d, a, b, x[k+10], S13, 0xFFFF5BB1);
					b = FF(b, c, d, a, x[k+11], S14, 0x895CD7BE);
					a = FF(a, b, c, d, x[k+12], S11, 0x6B901122);
					d = FF(d, a, b, c, x[k+13], S12, 0xFD987193);
					c = FF(c, d, a, b, x[k+14], S13, 0xA679438E);
					b = FF(b, c, d, a, x[k+15], S14, 0x49B40821);
					a = GG(a, b, c, d, x[k+1],  S21, 0xF61E2562);
					d = GG(d, a, b, c, x[k+6],  S22, 0xC040B340);
					c = GG(c, d, a, b, x[k+11], S23, 0x265E5A51);
					b = GG(b, c, d, a, x[k+0],  S24, 0xE9B6C7AA);
					a = GG(a, b, c, d, x[k+5],  S21, 0xD62F105D);
					d = GG(d, a, b, c, x[k+10], S22, 0x2441453);
					c = GG(c, d, a, b, x[k+15], S23, 0xD8A1E681);
					b = GG(b, c, d, a, x[k+4],  S24, 0xE7D3FBC8);
					a = GG(a, b, c, d, x[k+9],  S21, 0x21E1CDE6);
					d = GG(d, a, b, c, x[k+14], S22, 0xC33707D6);
					c = GG(c, d, a, b, x[k+3],  S23, 0xF4D50D87);
					b = GG(b, c, d, a, x[k+8],  S24, 0x455A14ED);
					a = GG(a, b, c, d, x[k+13], S21, 0xA9E3E905);
					d = GG(d, a, b, c, x[k+2],  S22, 0xFCEFA3F8);
					c = GG(c, d, a, b, x[k+7],  S23, 0x676F02D9);
					b = GG(b, c, d, a, x[k+12], S24, 0x8D2A4C8A);
					a = HH(a, b, c, d, x[k+5],  S31, 0xFFFA3942);
					d = HH(d, a, b, c, x[k+8],  S32, 0x8771F681);
					c = HH(c, d, a, b, x[k+11], S33, 0x6D9D6122);
					b = HH(b, c, d, a, x[k+14], S34, 0xFDE5380C);
					a = HH(a, b, c, d, x[k+1],  S31, 0xA4BEEA44);
					d = HH(d, a, b, c, x[k+4],  S32, 0x4BDECFA9);
					c = HH(c, d, a, b, x[k+7],  S33, 0xF6BB4B60);
					b = HH(b, c, d, a, x[k+10], S34, 0xBEBFBC70);
					a = HH(a, b, c, d, x[k+13], S31, 0x289B7EC6);
					d = HH(d, a, b, c, x[k+0],  S32, 0xEAA127FA);
					c = HH(c, d, a, b, x[k+3],  S33, 0xD4EF3085);
					b = HH(b, c, d, a, x[k+6],  S34, 0x4881D05);
					a = HH(a, b, c, d, x[k+9],  S31, 0xD9D4D039);
					d = HH(d, a, b, c, x[k+12], S32, 0xE6DB99E5);
					c = HH(c, d, a, b, x[k+15], S33, 0x1FA27CF8);
					b = HH(b, c, d, a, x[k+2],  S34, 0xC4AC5665);
					a = II(a, b, c, d, x[k+0],  S41, 0xF4292244);
					d = II(d, a, b, c, x[k+7],  S42, 0x432AFF97);
					c = II(c, d, a, b, x[k+14], S43, 0xAB9423A7);
					b = II(b, c, d, a, x[k+5],  S44, 0xFC93A039);
					a = II(a, b, c, d, x[k+12], S41, 0x655B59C3);
					d = II(d, a, b, c, x[k+3],  S42, 0x8F0CCC92);
					c = II(c, d, a, b, x[k+10], S43, 0xFFEFF47D);
					b = II(b, c, d, a, x[k+1],  S44, 0x85845DD1);
					a = II(a, b, c, d, x[k+8],  S41, 0x6FA87E4F);
					d = II(d, a, b, c, x[k+15], S42, 0xFE2CE6E0);
					c = II(c, d, a, b, x[k+6],  S43, 0xA3014314);
					b = II(b, c, d, a, x[k+13], S44, 0x4E0811A1);
					a = II(a, b, c, d, x[k+4],  S41, 0xF7537E82);
					d = II(d, a, b, c, x[k+11], S42, 0xBD3AF235);
					c = II(c, d, a, b, x[k+2],  S43, 0x2AD7D2BB);
					b = II(b, c, d, a, x[k+9],  S44, 0xEB86D391);
					a = addUnsigned(a, AA);
					b = addUnsigned(b, BB);
					c = addUnsigned(c, CC);
					d = addUnsigned(d, DD);
				}
				var tempValue = wordToHex(a) + wordToHex(b) + wordToHex(c) + wordToHex(d);
				return tempValue.toLowerCase();
			}
		});
	})(jQuery);

alert($.md5("Hello").toUpperCase()); 


结果: 8B1A9953C4611296A827ABF8C47804D7
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值