Message Digest Algorithm MD5(中文名为消息摘要算法第五版)为计算机安全领域广泛使用的一种散列函数,用以提供消息的完整性保护。该算法的文件号为RFC 1321(R.Rivest,MIT Laboratory for Computer Science and RSA Data Security Inc. April 1992)。
/** * Updates the digest using the specified array of bytes. * * @param input the array of bytes. */ public void update(byte[] input) { engineUpdate(input, 0, input.length); state = IN_PROGRESS; }
调用了engineUpdate方法,此方法进行一个更新操作。
1
Updates the digest using the specified array of bytes, starting at the specified offset.
然后state属性的状态就被改变了,表明当前计算正在处理过程中。
state默认属性
1
private int state = INITIAL;
然后需要调用MessageDigest.digest()方法计算哈希值
1 2 3 4 5 6 7 8 9 10 11 12
/** * Completes the hash computation by performing final operations * such as padding. The digest is reset after this call is made. * * @return the array of bytes for the resulting hash value. */ public byte[] digest() { /* Resetting is the responsibility of implementors. */ byte[] result = engineDigest(); state = INITIAL; return result; }