Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
这是我正在谈论的代码:
md.reset();
reset() 方法对 MessageDigest 对象有什么作用?为什么有必要?
它将 MessageDigest 实例返回到其初始状态,以便您可以再次使用它来计算另一个消息摘要(而不是获取新实例,这可能很昂贵或不方便)。
如果您没有调用此方法,而是继续将第二条消息推入,则生成的摘要可能不正确(因为它可能包含先前计算留下的“垃圾”)。