?? md5.java
字號:
a += (b ^ c ^ d) + x[1] + 0xa4beea44; /* 37 */ a = ((a << 4) | (a >>> 28)) + b; d += (a ^ b ^ c) + x[4] + 0x4bdecfa9; /* 38 */ d = ((d << 11) | (d >>> 21)) + a; c += (d ^ a ^ b) + x[7] + 0xf6bb4b60; /* 39 */ c = ((c << 16) | (c >>> 16)) + d; b += (c ^ d ^ a) + x[10] + 0xbebfbc70; /* 40 */ b = ((b << 23) | (b >>> 9)) + c; a += (b ^ c ^ d) + x[13] + 0x289b7ec6; /* 41 */ a = ((a << 4) | (a >>> 28)) + b; d += (a ^ b ^ c) + x[0] + 0xeaa127fa; /* 42 */ d = ((d << 11) | (d >>> 21)) + a; c += (d ^ a ^ b) + x[3] + 0xd4ef3085; /* 43 */ c = ((c << 16) | (c >>> 16)) + d; b += (c ^ d ^ a) + x[6] + 0x04881d05; /* 44 */ b = ((b << 23) | (b >>> 9)) + c; a += (b ^ c ^ d) + x[9] + 0xd9d4d039; /* 33 */ a = ((a << 4) | (a >>> 28)) + b; d += (a ^ b ^ c) + x[12] + 0xe6db99e5; /* 34 */ d = ((d << 11) | (d >>> 21)) + a; c += (d ^ a ^ b) + x[15] + 0x1fa27cf8; /* 35 */ c = ((c << 16) | (c >>> 16)) + d; b += (c ^ d ^ a) + x[2] + 0xc4ac5665; /* 36 */ b = ((b << 23) | (b >>> 9)) + c; /* Round 4 */ a += (c ^ (b | ~d)) + x[0] + 0xf4292244; /* 49 */ a = ((a << 6) | (a >>> 26)) + b; d += (b ^ (a | ~c)) + x[7] + 0x432aff97; /* 50 */ d = ((d << 10) | (d >>> 22)) + a; c += (a ^ (d | ~b)) + x[14] + 0xab9423a7; /* 51 */ c = ((c << 15) | (c >>> 17)) + d; b += (d ^ (c | ~a)) + x[5] + 0xfc93a039; /* 52 */ b = ((b << 21) | (b >>> 11)) + c; a += (c ^ (b | ~d)) + x[12] + 0x655b59c3; /* 53 */ a = ((a << 6) | (a >>> 26)) + b; d += (b ^ (a | ~c)) + x[3] + 0x8f0ccc92; /* 54 */ d = ((d << 10) | (d >>> 22)) + a; c += (a ^ (d | ~b)) + x[10] + 0xffeff47d; /* 55 */ c = ((c << 15) | (c >>> 17)) + d; b += (d ^ (c | ~a)) + x[1] + 0x85845dd1; /* 56 */ b = ((b << 21) | (b >>> 11)) + c; a += (c ^ (b | ~d)) + x[8] + 0x6fa87e4f; /* 57 */ a = ((a << 6) | (a >>> 26)) + b; d += (b ^ (a | ~c)) + x[15] + 0xfe2ce6e0; /* 58 */ d = ((d << 10) | (d >>> 22)) + a; c += (a ^ (d | ~b)) + x[6] + 0xa3014314; /* 59 */ c = ((c << 15) | (c >>> 17)) + d; b += (d ^ (c | ~a)) + x[13] + 0x4e0811a1; /* 60 */ b = ((b << 21) | (b >>> 11)) + c; a += (c ^ (b | ~d)) + x[4] + 0xf7537e82; /* 61 */ a = ((a << 6) | (a >>> 26)) + b; d += (b ^ (a | ~c)) + x[11] + 0xbd3af235; /* 62 */ d = ((d << 10) | (d >>> 22)) + a; c += (a ^ (d | ~b)) + x[2] + 0x2ad7d2bb; /* 63 */ c = ((c << 15) | (c >>> 17)) + d; b += (d ^ (c | ~a)) + x[9] + 0xeb86d391; /* 64 */ b = ((b << 21) | (b >>> 11)) + c; state.state[0] += a; state.state[1] += b; state.state[2] += c; state.state[3] += d; System.gc(); } /** * Updates hash with the bytebuffer given (using at maximum length bytes * from that buffer) * * @param stat * Which state is updated * @param buffer * Array of bytes to be hashed * @param offset * Offset to buffer array * @param length * Use at maximum `length' bytes (absolute maximum is * buffer.length) */ private final void update(MD5State stat, byte buffer[], int offset, int length) { int index, partlen, i, start; finals = null; /* Length can be told to be shorter, but not inter */ if ((length - offset) > buffer.length) length = buffer.length - offset; /* compute number of bytes mod 64 */ index = (int) (stat.count & 0x3f); stat.count += length; partlen = 64 - index; if (length >= partlen) { // update state (using only Java) to reflect input int[] decode_buf = new int[16]; if (partlen == 64) { partlen = 0; } else { for (i = 0; i < partlen; i++) stat.buffer[i + index] = buffer[i + offset]; transform(stat, stat.buffer, 0, decode_buf); } for (i = partlen; (i + 63) < length; i += 64) { transform(stat, buffer, i + offset, decode_buf); } index = 0; } else i = 0; /* buffer remaining input */ if (i < length) { start = i; for (; i < length; i++) { stat.buffer[index + i - start] = buffer[i + offset]; } } } private static final byte[] encode( final int input[], final int len) { int i, j; byte out[]; out = new byte[len]; for (i = j = 0; j < len; i++, j += 4) { out[j] = (byte) (input[i] & 0xff); out[j + 1] = (byte) ((input[i] >>> 8) & 0xff); out[j + 2] = (byte) ((input[i] >>> 16) & 0xff); out[j + 3] = (byte) ((input[i] >>> 24) & 0xff); } return out; } public MD5( byte[] data ) { state = new MD5State(); finals = null; update( data ); } /** * Updates hash with given array of bytes * * @param buffer * Array of bytes to use for updating the hash */ public final void update( final byte buffer[]) { if( buffer == null ) return; this.state = new MD5State(); update( state, buffer,0, buffer.length ); } /** * Returns array of bytes (16 bytes) representing hash as of the current * state of this object. Note: getting a hash does not invalidate the hash * object, it only creates a copy of the real state which is finalized. * * @return Array of 16 bytes, the hash of all updated bytes */ public synchronized final byte[] doFinal() { byte bits[]; int index, padlen; MD5State fin; if (finals == null) { fin = new MD5State(state); int[] count_ints = { (int) (fin.count << 3),(int) (fin.count >> 29) }; bits = encode(count_ints, 8); index = (int) (fin.count & 0x3f); padlen = (index < 56) ? (56 - index) : (120 - index); update(fin, padding, 0, padlen); update(fin, bits, 0, 8); /* Update() sets finals to null */ finals = fin; } return encode(finals.state, 16); } /** * Returns 32-character hex representation of this objects hash * * @return String of this object's hash */ public static final String toHex( final byte[] hash ) { char buf[] = new char[hash.length * 2]; for (int i = 0, x = 0; i < hash.length; i++) { buf[x++] = HEX_CHARS[(hash[i] >>> 4) & 0xf]; buf[x++] = HEX_CHARS[hash[i] & 0xf]; } return new String(buf); } public static final String toBase64( final byte[] data ) { char[] alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".toCharArray(); char[] out = new char[((data.length + 2) / 3) * 4]; for (int i=0, index=0; i<data.length; i+=3, index+=4) { boolean quad = false; boolean trip = false; int val = (0xFF & data[i]); val <<= 8; if ((i+1) < data.length) { val |= (0xFF & data[i+1]); trip = true; } val <<= 8; if ((i+2) < data.length) { val |= (0xFF & data[i+2]); quad = true; } out[index+3] = alphabet[(quad? (val & 0x3F): 64)]; val >>= 6; out[index+2] = alphabet[(trip? (val & 0x3F): 64)]; val >>= 6; out[index+1] = alphabet[val & 0x3F]; val >>= 6; out[index+0] = alphabet[val & 0x3F]; } return new String( out ); } /** * Calculates and returns the hash of the contents of the given file. */ public final byte[] fingerprint(final byte[] data) { update( data ); return doFinal(); } /** * @return true iff the first 16 bytes of both hash1 and hash2 are equal; * both hash1 and hash2 are null; or either hash array is less than * 16 bytes in length and their lengths and all of their bytes are * equal. */ public static final boolean equals(byte[] hash1, byte[] hash2) { if (hash1 == null) return hash2 == null; if (hash2 == null) return false; int targ = 16; if (hash1.length < 16) { if (hash2.length != hash1.length) return false; targ = hash1.length; } else if (hash2.length < 16) { return false; } for (int i = 0; i < targ; i++) { if (hash1[i] != hash2[i]) return false; } return true; }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -