基于J2ME的MD5算法类
//实现MD5算法的类,提供一个静态的函数toMD5()供调用; //还提供一个getMD5ofStr()函数生成一个MD5加密串; public class MD5 { static final int S11 = 7; static final int S12 = 12; static final int S13 = 17; static final int S14 = 22; static final int S21 = 5; static final int S22 = 9; static final int S23 = 14; static final int S24 = 20; static final int S31 = 4; static final int S32 = 11; static final int S33 = 16; static final int S34 = 23; static final int S41 = 6; static final int S42 = 10; static final int S43 = 15; static final int S44 = 21; static final char Hex[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; static final byte PADDING[] = { -128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; private long state[]; private long count[]; private byte buffer[]; public String digestHexStr; private byte digest[]; private byte test; public String getMD5ofStr(String s) {//返回MD5串; int i; md5Init(); md5Update(s.getBytes(), s.length()); md5Final(); digestHexStr = ""; for(i = 0;i<16;i++) digestHexStr=digestHexStr+byteHEX(digest[i]); return digestHexStr; } public MD5() { state = new long[4]; count = new long[2]; buffer = new byte[64]; digest = new byte[16]; md5Init(); } private void md5Init() {//初始化部分变量; count[0] = 0L; count[1] = 0L; state[0] = 0x67452301L; 本新闻共 6页,当前在第 1页 1 2 3 4 5 6 |