Solved

Message Digest of char array

Posted on 2007-03-30
6
328 Views
Last Modified: 2013-12-29
I'm trying to create a message digest for a password, which is stored as a char array.

Currently, I'm doing something like this:

char [] password ;
...
MessageDigest md5=MessageDigest.getInstance("MD5");
md5.update(new String(password).getBytes("UTF8"));
byte [] md = md5.digest();

Which works. However, converting it to a string [in order to get a byte array for it] defeats the entire point of storing the password as a char array in the first place..

So is there a direct way of achieving this, without incorporating java.lang.String?


Thanks
0
Comment
Question by:InteractiveMind
  • 2
6 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 168 total points
ID: 18822681
The password shouldn't be stored anywhere client-side, in whatever form
0
 
LVL 10

Assisted Solution

by:ADSLMark
ADSLMark earned 166 total points
ID: 18822729
A character is 2 bytes long and a byte is 1 byte long.. so if you want to convert a char[] to a byte[], then your solution seems best.
The message digest works on bytes only anyway..

Mark
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 18822739
If you plump for low security and store it client-side, then of course you could store it as UTF byte[]
0
 
LVL 30

Assisted Solution

by:mayankeagle
mayankeagle earned 166 total points
ID: 18825626
>> byte [] md = md5.digest();

You're storing it as a byte[] so it looks fine to me.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
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…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

757 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

19 Experts available now in Live!

Get 1:1 Help Now