Image hash's output String always has "null" at the beginning

I'm trying to hash an image and show the hash result in string in text field, the code is working but the result always has "null" at the beginning of the hash 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? Is it a part of the hash code or a bug? 2. If "null" is a bug, how I can make it not included in the result?

-------------Problems Reply------------

You set the string to null then append to it; what else could happen?

Set it to an empty string to initialize it, e.g., String hexString = "";

Category:java Views:3 Time:2017-09-07
Tags: java hash android

Related post

  • Prism RegionManager.Region[""].GetView("string") always returns null 2011-03-29

    I have an import in my view model for the regionmanager [Import] private IRegionManager _regionManager; I want to be able to get a view and remove it from a region. First step, get the view i.e. _regionManager.Regions["MainRegion"].GetView("ViewName"

  • SQLite always returns (null) for the TEXT value in iphone 2011-11-07

    I am trying to retrive data from my table. But it always returns (null). Here is my code -(NSString *)filePath { NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentDir=[paths objectAtInde

  • Checking if a url has http:// at the beginning & inserting if not 2011-12-21

    This question already has an answer here: How to add http:// if it's not exists in the URL? 9 answers I am currently editing a wordpress theme with custom field outputs. I have successfully made all the edits and everything works as it should. My pro

  • on clicking a text view, always positioning cursor at the beginning 2012-02-29

    I have a text view. I have not implemented the UITextView Delegate Protocol in my .h, but in .m file I am overriding the delegate methods (shouldBeginEditing and endEditing) and the methods are getting called. Now, what I want to do is whenever user

  • mapping WCF getURL to string always returns NULL (Taleo SOAP) 2011-01-13

    QUICK SUMMARY: Taleo has a single operation "Dispatcher WSDL" that is supposed to return a URL for use with its WebAPI WSDL ... the purpose is to allow the URL to be for all intents and purposes soft coded. For operation getURL, WcfTestClient.exe XML

  • Will std::string always be null-terminated in C++11? 2011-05-20

    In a 2008 post on his site, Herb Sutter states the following: There is an active proposal to tighten this up further in C++0x and require null-termination and possibly ban copy-on-write implementations, for concurrency-related reasons. Here’s the pap

  • Sencha Touch 2 - JSONP proxy help, template always has null for values 2012-03-16

    I'm having trouble getting actual data to show up in a Sencha Touch 2 list. The list should be populated by a JSONP response, and I expect 2 rows to show up. Instead, I get one row with 'null at null'. Here's the URL that gets sent: http://some-serve

  • Server socket always return null to the client , Java 2012-02-09

    I, doing some computer network homework and I have to develop some sort of distributed DBMS which are connected to each other with peer to peer network, so I have a TCP client and a TCP server in one .java file which running next to each other by thr

  • ServletRequest.getParameter always returns null when the post size is big 2011-09-13

    We are maintaining a spring mvc (2.5.6) web application running on Tomcat 6.0.14 There is a bug in our app that caused one text field to increase its size resulting in a post of 3.000.000 bytes of text. We will fix this bug, but what bothers me is th

  • How can I delete chars from a string from point X to the beginning 2009-10-22

    I have a string of source code HTML. So I would go: int X = find indexof("theterm"); thesourcecode = thesourcecode.Substring(???? How can I delete all chars from the point where theterm is found BEHIND? Thanks SO. Edit: An example so people dont' get

  • Sort NSArray of NSStrings by a containing Number in the String. Rearrange String so Number is in the beginning? 2011-05-16

    I have an array of string, that look like this "/var/folders/zy/zy4FzDGQEUuq9jZ1hTRFHk+++TI/-Tmp-/tarDir0172809001305545247/0516_GTB_HP_01.pdf" "/var/folders/zy/zy4FzDGQEUuq9jZ1hTRFHk+++TI/-Tmp-/tarDir0172809001305545247/0516_ETB_HP_28.pdf" As you ca

  • How to split a string with whitespace chars at the beginning? 2011-10-31

    Quick example: public class Test { public static void main(String[] args) { String str = " a b"; String[] arr = str.split("\\s+"); for (String s : arr) System.out.println(s); } } I want the array arr to contain 2 elements: "a" and "b", but in the res

  • How to strip an image from a paragraph, and then move it to the beginning of paragraph 2011-11-01

    I am trying to figure out how to move an image in a small paragraph of text using regex, so that for example: this is a <img src="image.jpg" /> paragraph turns into <img src="image.jpg" /> this is a paragraph Does anyone have any ideas pl

  • config.getInitParameter always return null 2011-12-06

    Why does config.getInitParameter(String) always return null in the following code example? public void init(ServletConfig config) throws ServletException { super.init(config); filename = config.getInitParameter("addressfile"); This is web.xml file

  • What is image hashing used for? 2009-06-15

    I hear this term sometimes and am wondering what it is used for? --------------Solutions------------- While normally hashing a file hashes the individual bits of data of the file, image hashing works on a slightly higher level. The difference is that

  • Replace always replacing null values 2010-05-03

    Why does left(FIELD, replace(nullif(charindex('-', FIELD), 0), null, len(FIELD))) always return null? The idea behind the query is that if charindex() returns 0, then convert the results into null, then convert the null into the length of the field.

  • getRequestProperty("Authorization") always returns null 2010-05-19

    I am trying to read the authorization header for an HTTP request (because I need to add something to it), but I always get null for the header value. Other headers work fine. public void testAuth() throws MalformedURLException, IOException{ URLConnec

  • A TableRow referenced trought a DataRelation always returns null 2011-02-27

    Using the DataSet designer in Visual Studio 2010, I've added some tables from a MySql DB. VS10 automatically picks up and adds the relations between the tables, e.g., the relation "FK_organisatie_adres" between the tables "Organisatie" and "Adres": I

  • Create a 16 Bit TIFF image from a Python string 2011-08-07

    I need to use scanner in 16 bit depth and color mode, so i modified python-imaging-sane (that doesn't support RGB tiff with 16 bit depth) to receive from a scanner (epson v500) an image in a Python string. this is the modified function that i use to

  • What is really happen (actual process) when we hash a particular string or word 2012-02-14

    Hi am trying to develop a counting bloom filter in java. i really searched most of the sources about the bloom filter.. The thing i understood is when we hash (do hashing) the particular string or word, the result of hashing will return one value so

  • C# Strings - Why does null give me a different result as opposed to ""? 2012-04-04

    I have 2 forms set up. In the first form I have the following code. frm_BL addBranch = new frm_BL(); do { addBranch.ShowDialog(); if (addBranch.txtAmount.Text == "") { break; } } while (true); In the main form. And just this in the second form. priva

  • Session object always returns null in asp mvc? 2016-05-06

    I'm developing a website in asp mvc but i'm having trouble with Session objects. i have this class for managing sessions,with a property for storing the language: public class SessionManager { public static string Language { get { object language = G

  • how to Remove and all other html tags from tha output string not at the time of input string in PHP? 2011-04-20

    I am wondering to know how it can be possible to remove the tags from output string in PHP. At the time of input It can be removed by strip_tags() that I know but From already generated output where html tags appeared, How it can be removed ? For exa

  • GWT getting image from database using RPC and display it in the UI 2013-06-07

    I am trying to make an image uploading widget and store the image in the GWT database so it can be read from it later. Here's the code: Servlet (HttpServletRequest request) /* */ iter = upload.getItemIterator(request); while (iter.hasNext()) { FileIt

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.169 (s). 11 q(s)