图像散列的输出字符串总是以 "null" 开头
Image hash's output String always has "null" at the beginning
我正在尝试对图像进行哈希处理,并在文本字段中以字符串形式显示哈希结果,代码可以正常工作,但结果总是在哈希代码的开头有 "null"。
bitmap1 = BitmapFactory.decodeFile(picturePath1,opt);
ImageView view1 = (ImageView) findViewById(R.id.gambar5);
view1.setImageBitmap(bitmap1);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
bitmap1.compress(Bitmap.CompressFormat.PNG, 100, outputStream);
byte[] data1 = outputStream.toByteArray();
MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update(data1);
byte[] hash = md.digest();
String result = returnHex(hash);
EditText et1 = (EditText) findViewById(R.id.editText1);
et1.setText(result);
我正在使用此站点的 returnHex 函数
returnHex
这是功能代码
static String returnHex(byte[] inBytes) throws Exception {
String hexString = null;
for (int i=0; i < inBytes.length; i++) { //for loop ID:1
hexString += Integer.toString( ( inBytes[i] & 0xff ) + 0x100, 16).substring( 1 );
}// Belongs to for loop ID:1
return hexString;
}
结果总是 return 和 "null" 就像一个例子:null8984fb2c1ba6ec6571d365553e466c95c94eba9d6fb2079af03
我的问题是:
1、总是出现的"null"是什么?它是哈希码的一部分还是错误?
2. 如果 "null" 是一个错误,我怎样才能让它不包含在结果中?
您将字符串设置为 null
然后附加到它;还会发生什么?
将其设置为空字符串以对其进行初始化,例如,String hexString = "";
我正在尝试对图像进行哈希处理,并在文本字段中以字符串形式显示哈希结果,代码可以正常工作,但结果总是在哈希代码的开头有 "null"。
bitmap1 = BitmapFactory.decodeFile(picturePath1,opt);
ImageView view1 = (ImageView) findViewById(R.id.gambar5);
view1.setImageBitmap(bitmap1);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
bitmap1.compress(Bitmap.CompressFormat.PNG, 100, outputStream);
byte[] data1 = outputStream.toByteArray();
MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update(data1);
byte[] hash = md.digest();
String result = returnHex(hash);
EditText et1 = (EditText) findViewById(R.id.editText1);
et1.setText(result);
我正在使用此站点的 returnHex 函数 returnHex
这是功能代码
static String returnHex(byte[] inBytes) throws Exception {
String hexString = null;
for (int i=0; i < inBytes.length; i++) { //for loop ID:1
hexString += Integer.toString( ( inBytes[i] & 0xff ) + 0x100, 16).substring( 1 );
}// Belongs to for loop ID:1
return hexString;
}
结果总是 return 和 "null" 就像一个例子:null8984fb2c1ba6ec6571d365553e466c95c94eba9d6fb2079af03
我的问题是: 1、总是出现的"null"是什么?它是哈希码的一部分还是错误? 2. 如果 "null" 是一个错误,我怎样才能让它不包含在结果中?
您将字符串设置为 null
然后附加到它;还会发生什么?
将其设置为空字符串以对其进行初始化,例如,String hexString = "";