Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

byte array to hex

Posted on 2014-01-31
5
Medium Priority
?
347 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

604 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