Click here to Skip to main content
15,567,482 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
String senc = "String to encode"; digest ="MD5");

What to do next to get the String with MD5?
EDIT: Is this possible at all? (using built in md5-support)
I can't found working examples:(
Please, help.

byte msgDigest[] = algorithm.digest();//==> error occurs

required: byte[], int, int.
found: no arguments.
Ok, I wrote:
byte msgDigest[] = algorithm.digest(sencBytes, 0, sencBytes.length);

and i got an error again:
required: byte[], int, int.
found: int
I don't know why found int if first argument is byte[] :(

Project properties:
Device Configuration: CLDC-1.1
Device Profile: MIDP-2.1
Updated 10-Nov-10 3:17am

1 solution

It shows you haven't opened the Java Documentation.
Anyways the following is the way to implement MD5 Message Digest. Hope it helps.

String senc = "String to encode";
byte[] sencBytes = senc.getBytes();
	MessageDigest algorithm = MessageDigest.getInstance("MD5");
	byte msgDigest[] = algorithm.digest();
	StringBuffer md5String = new StringBuffer();
	for (int i=0;i<msgDigest.length;i++) {
		md5String.append(Integer.toHexString(0xFF & msgDigest[i]));
	String foo = msgDigest.toString();
	System.out.println("MD5 of "+senc+" is "+md5String.toString());
}catch(NoSuchAlgorithmException nsae){
            JOptionPane.showMessageDialog(null, "Warning!!", "No Such Alogorithm Available", JOptionPane.ERROR_MESSAGE);
Share this answer
[no name] 10-Nov-10 8:06am    
Thanks, but I don't know why your code not works for me..
Indivara 10-Nov-10 8:36am    
You need to say _what_ doesn't work
[no name] 10-Nov-10 8:44am    
I tested GPUToaster's code and edited my first post to show what doesn't work.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900