Solved

byte array to hex

Posted on 2014-01-31
5
312 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
  • 3
5 Comments
 
LVL 26

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 35

Expert Comment

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

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 26

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
This video teaches viewers about errors in exception handling.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now