知识大全 md5算法的java源代码
Posted 知
篇首语:满堂花醉三千客,一剑霜寒十四州。本文由小常识网(cha138.com)小编为大家整理,主要介绍了知识大全 md5算法的java源代码相关的知识,希望对你有一定的参考价值。
public class MD /* * A Java implementation of the RSA Data Security Inc MD Message * Digest Algorithm as defined in RFC * Based on the JavaScript implementation of Paul Johnston * Copyright (C) Paul Johnston * See for details * Java Version by Thomas Weber (Orange Interactive GmbH) */ /* * Convert a bit number to a hex string with ls byte first */ String hex_chr = abcdef ; private String rhex(int num) String str = ; for(int j = ; j <= 3; j++) str = str + hex_chr.charAt((num >> (j * + )) & x F) + hex_chr charAt((num >> (j * )) & x F); return str; /* * Convert a string to a sequence of word blocks stored as an array * Append padding bits and the length as described in the MD standard */ private int[] str blks_MD (String str) int nblk = ((str length() + ) >> ) + ; int[] blks = new int[nblk * ]; int i = ; for(i = ; i < nblk * ; i++) blks[i] = ; for(i = ; i < str length(); i++) blks[i >> ] |= str charAt(i) << ((i % ) * ); blks[i >> ] |= x << ((i % ) * ); blks[nblk * ] = str length()* ; return blks; /* * Add integers wrapping at ^ */ private int add(int x int y) return ((x& x FFFFFFF) + (y& x FFFFFFF)) ^ (x& x ) ^ (y& x ); /* * Biise rotate a bit number to the left */ private int rol(int num int cnt) return (num << cnt) | (num >>> ( cnt)); /* * These functions implement the basic operation for each round of the * algorithm */ private int cmn(int q int a int b int x int s int t) return add(rol(add(add(a q) add(x t)) s) b); private int ff(int a int b int c int d int x int s int t) return cmn((b & c) | ((~b) & d) a b x s t); private int gg(int a int b int c int d int x int s int t) return cmn((b & d) | (c & (~d)) a b x s t); private int hh(int a int b int c int d int x int s int t) return cmn(b ^ c ^ d a b x s t); private int ii(int a int b int c int d int x int s int t) return cmn(c ^ (b | (~d)) a b x s t); /* * Take a string and return the hex representation of its MD */ public String calcMD (String str) int[] x = str blks_MD (str); int a = x ; int b = xEFCDAB ; int c = x BADCFE; int d = x ; for(int i = ; i < x length; i += ) int olda = a; int oldb = b; int oldc = c; int oldd = d; a = ff(a b c d x[i+ ] xD AA ); d = ff(d a b c x[i+ ] xE C B ); c = ff(c d a b x[i+ ] x DB); b = ff(b c d a x[i+ ] xC BDCEEE); a = ff(a b c d x[i+ ] xF C FAF); d = ff(d a b c x[i+ ] x C A); c = ff(c d a b x[i+ ] xA ); b = ff(b c d a x[i+ ] xFD ); a = ff(a b c d x[i+ ] x D ); d = ff(d a b c x[i+ ] x B F AF); c = ff(c d a b x[i+ ] xFFFF BB ); b = ff(b c d a x[i+ ] x CD BE); a = ff(a b c d x[i+ ] x B ); d = ff(d a b c x[i+ ] xFD ); c = ff(c d a b x[i+ ] xA E); b = ff(b c d a x[i+ ] x B ); a = gg(a b c d x[i+ ] xF E ); d = gg(d a b c x[i+ ] xC B ); c = gg(c d a b x[i+ ] x E A ); b = gg(b c d a x[i+ ] xE B C AA); a = gg(a b c d x[i+ ] xD F D); d = gg(d a b c x[i+ ] x ); c = gg(c d a b x[i+ ] xD A E ); b = gg(b c d a x[i+ ] xE D FBC ); a = gg(a b c d x[i+ ] x E CDE ); d = gg(d a b c x[i+ ] xC D ); c = gg(c d a b x[i+ ] xF D D ); b = gg(b c d a x[i+ ] x A ED); a = gg(a b c d x[i+ ] xA E E ); d = gg(d a b c x[i+ ] xFCEFA F ); c = gg(c d a b x[i+ ] x F D ); b = gg(b c d a x[i+ ] x D A C A); a = hh(a b c d x[i+ ] xFFFA ); d = hh(d a b c x[i+ ] x F ); c = hh(c d a b x[i+ ] x D D ); b = hh(b c d a x[i+ ] xFDE C); a = hh(a b c d x[i+ ] xA BEEA ); d = hh(d a b c x[i+ ] x BDECFA ); c = hh(c d a b x[i+ ] xF BB B ); b = hh(b c d a x[i+ ] xBEBFBC ); a = hh(a b c d x[i+ ] x B EC ); d = hh(d a b c x[i+ ] xEAA FA); c = hh(c d a b x[i+ ] xD EF ); b = hh(b c d a x[i+ ] x D ); a = hh(a b c d x[i+ ] xD D D ); d = hh(d a b c x[i+ ] xE DB E ); c = hh(c d a b x[i+ ] x FA CF ); b = hh(b c d a x[i+ ] xC AC ); a = ii(a b c d x[i+ ] xF ); d = ii(d a b c x[i+ ] x AFF ); c = ii(c d a b x[i+ ] xAB A ); b = ii(b c d a x[i+ ] xFC A ); a = ii(a b c d x[i+ ] x B C ); d = ii(d a b c x[i+ ] x F CCC ); c = ii(c d a b x[i+ ] xFFEFF D); b = ii(b c d a x[i+ ] x DD ); a = ii(a b c d x[i+ ] x FA E F); d = ii(d a b c x[i+ ] xFE CE E ); c = ii(c d a b x[i+ ] xA ); b = ii(b c d a x[i+ ] x E A ); a = ii(a b c d x[i+ ] xF E ); d = ii(d a b c x[i+ ] xBD AF ); c = ii(c d a b x[i+ ] x AD D BB); b = ii(b c d a x[i+ ] xEB D ); a = add(a olda); b = add(b oldb); c = add(c oldc); d = add(d oldd); return rhex(a) + rhex(b) + rhex(c) + rhex(d); 另: 一中国人写的md 的javabean: /************************************************ MD 算法的Java Bean @author:Topcat Tuppin Last Modified: Mar *************************************************/ //package beartool; import java lang reflect *; /************************************************* md 类实现了RSA Data Security Inc 在提交给IETF 的RFC 中的MD message digest 算法 *************************************************/ public class MD /* 下面这些S S 实际上是一个 * 的矩阵 在原始的C实现中是用#define 实现的 这里把它们实现成为static final是表示了只读 切能在同一个进程空间内的多个 Instance间共享*/ static final int S = ; static final int S = ; static final int S = ; static final int S = ; static final int S = ; static final int S = ; static final int S = ; static final int S = ; static final int S = ; static final int S = ; static final int S cha138/Article/program/Java/hx/201311/26958相关参考
java中使用MD5加密算法进行加密 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! 在各种应用系
Java中常用的加密算法MD5,SHA,RSA 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! M
利用DES加密算法保护Java源代码 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! Java语言
ASP.NET中使用MD5和SHA1算法加密 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! 你的
知识大全 MD5算法的T-SQL实现(FOR SQL2000)(二)
MD5算法的T-SQL实现(FORSQL2000)(二) 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下
一利用二进制状态法求排列组合此种方法比较容易懂但是运行效率不高小数据排列组合可以使用复制代码代码如下:importjavautilArrays; //利用二进制算法进行全排列//count://
Java代码 插入排序: packagerututilalgorithmsupport; importrututilalgorithmSortUtil; publicclassInse
可变MD5加密(Java实现) 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! 可变在这里含义很简
一个实现MD5的简洁的JAVA类 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! 由于消息摘要唯一
MD5的JavaBean实现 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! MD简介 MD的全