I'm new with Android and Java, I trying to hash some image and show the hash result in string in text field, the code is working but the result is kind of weird this is my code
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);
I'm using returnHex function from this site returnHex
this is the function code
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;
}
the result is always return with "null" like an ex: null8984fb2c1ba6ec6571d365553e466c95c94eba9d6fb2079af03
My question is: 1. what is the "null" that always show up? it is a part of hash code or a bug? 2. if "null" is a bugs, how i can make it not included in the result?
Regards,
sorry for my bad english, thank you before
0 comments:
Post a Comment