Solved

byte array to hex

Posted on 2014-01-31
5
332 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 500 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

Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

Question has a verified solution.

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

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

717 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