我正在做一个数据加密项目,只是想问一下如何使用消息摘要类的方法update。 在MD5实现的代码片段中,这样写的。
import java.security.MessageDigest;
import java.util.*;
class MD5{
public static void main(String[]args){
Scanner cin=new Scanner(System.in);
String s=cin.nextLine();
try{
MessageDigest md=MessageDigest.getInstance("MD5");
byte[] dataBytes=s.getBytes();
md.update(dataBytes,0,0);
byte[] digest=md.digest();
for(byte b:digest)System.out.printf("%02x",b);
}catch(Exception e){}
}
}
我对这一行感到困惑
md.update(dataBytes,0,0);
这三个参数的用途是什么?以及如何仅对特定数字(例如 192 字节的数据)进行哈希处理。
最佳答案
what are the three arguments are used for?
update(byte[] input, int offset, int len)
使用指定的字节数组更新摘要,从指定的偏移量开始。
input
是应该被散列的数组
offset
是数组的索引,是起点
len
指定距离起始索引多远
关于java - 如何使用消息摘要类的update方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47795808/