Solved

Message Digest of char array

Posted on 2007-03-30
6
334 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:Mayank S
Mayank S 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jsp login check 12 42
difference between sorce folder and folder in eclipise 3 28
Eclipse Java import and method not resolved 4 48
Java 8 to Java 6 8 20
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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 learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…

856 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