?
Solved

byte array to hex

Posted on 2014-01-31
5
Medium Priority
?
339 Views
Last Modified: 2014-02-12
Hi,

I am trying below example

http://www.avajava.com/tutorials/lessons/how-do-i-convert-a-byte-array-to-hex.html

I wonder what is the purpose and practical use od converting b yte aray to hex. And what is the use of md5 digest in this sceanario.
please advise
Any links resources ideas highly appreciated. Thanks in advance
0
Comment
Question by:gudii9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 28

Expert Comment

by:dpearson
ID: 39825861
You often convert a byte array (binary data) into hex (character data) so it's easy to send it or use it somewhere that only accepts characters.

E.g. Say you wanted to take a series of binary values and post them onto this website so we can see them.  If you convert them to hex you get a string of simple characters.  If you posted the binary, they wouldn't display in a readable form.

Does that make sense?

MD5 hashing is a separate process.  Hashing is the process where you convert one value (the plaintext value) into a new value (the hashed value).  The important thing about hashing is that it's a 1-way process.  If I have a particular plaintext value it will always hash to the same value (for a given hash function like MD5).  BUT more than one plaintext value will hash to the same hashed value.  So we can have:

Hash("ABC") = 123
Hash("XYZ") = 52
Hash("KLM") = 123 <- it's the same as Hash("ABC")

Because of this hashing is frequently used when storing passwords.  The trick is that when you enter your password, it is hashed and the hashed value is sent to the server to store.
When you come back to the site, you type in your password, it is hashed to the same value as before and matches the one stored.

BUT because the hashed value is all that is stored in the database and hashed values aren't unique for a given plaintext value, there is no chance that somebody could work backwards from the hashed value to the original password.

Anyway that's a lot to digest.

Doug
0
 
LVL 36

Expert Comment

by:mccarl
ID: 39828668
Anyway that's a lot to digest.
Doug, was the pun intended? ;)
0
 
LVL 28

Expert Comment

by:dpearson
ID: 39828816
Anyway that's a lot to digest.
Doug, was the pun intended? ;)

Haha - um no, not at all...
0
 
LVL 7

Author Comment

by:gudii9
ID: 39842902
The important thing about hashing is that it's a 1-way process.  If I have a particular plaintext value it will always hash to the same value (for a given hash function like MD5).  BUT more than one plaintext value will hash to the same hashed value.  So we can have:

Hash("ABC") = 123
Hash("XYZ") = 52
Hash("KLM") = 123 <- it's the same as Hash("ABC")

How ABC and KLM both has 123 as Hash value. can you please elaborate on that.
0
 
LVL 28

Accepted Solution

by:
dpearson earned 2000 total points
ID: 39843034
How ABC and KLM both has 123 as Hash value. can you please elaborate on that.

Open in new window


It's the nature of hash functions that they can do this.

Say for instance a simple hash function is:

int hash(String str) {
   return str.chatAt(0) ;
}

This will sort all strings into the same bucket that start with the same letter.  (This is sort of the algorithm you use in a real dictionary - thumb through the top to find the words starting with the letter you want, then proceed further in).

This is a perfectly legal hash function just not a very good one.

For that hash function you'd get that:

hash("ABC") = 65 ;
hash("DEF") = 68 ;
hash("ADE") = 65 ; // Same as for ABC because they start with the same letter

See how hash("ABC") == hash("ADE").

That's the way hashing is meant to work:
a) A given string always hashes to the same value
    hash("ABC") will always return 65.  It can't vary over time.

b) Multiple strings can hash to the same value
    hash("ABC") = hash("ADE") is fine.

Doug
0

Featured Post

Linux Academy Android App Now Supports Chromecast

We have some fantastic news for our Android fans. We’re so excited to announce that the Linux Academy Android app is now available with Chromecast support. That’s right – simply download the latest update of the Linux Academy App and start casting your favorite course videos!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn different types of Android Layout and some basics of an Android App.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month14 days, 16 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question