Solved

Message Digest of char array

Posted on 2007-03-30
6
340 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
[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
  • 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

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…
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…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
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 …

687 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