MD5 encryption question - communication with Java



Hey I am new to C# (My background is in Java),

I am writing a C# application (that uses the Compact Framework) that
communicates to a Java server. To login the server is expecting the
password to be MD5 encrypted, and then base64 encoded. The Java client
is doing this as follows, and it works with the server:

private static String encodePassword(String password) {

try {
MessageDigestalgorithm = MessageDigest.getInstance("MD5");
algorithm.reset();
algorithm.update(password.getBytes());
byte[] encrypted = algorithm.digest();

ByteArrayOutputStream out = new ByteArrayOutputStream();
OutputStream encoder = MimeUtility.encode(out, "base64");
encoder.write(encrypted);
return new String(out.toByteArray());

} catch (...exception code )
}
}

This returns a value of: ISMvKXpXpadDiUoOSoAf

In c# when I try to do this I get a very different value, The current
code is doing this...

System.Security.Cryptography.MD5 md5 =
System.Security.Cryptography.MD5.Create ();
byte[] encrypted =
md5.ComputeHash(System.Text.Encoding.ASCII.GetBytes(password));
string encoded = Convert.ToBase64String(encrypted, 0,
encrypted.Length);

This returns a value of: ISMvKXpXpadDiUoOSoAfww==

My questions are what would be causing the difference between the Java
output and the c# output? The Java server is expecting the first
value.

What is the proper way to do this?

And last, where is the best place to learn about this? I have been
doing a lot of looking on line, but wondering what the best site would
be to learn about some of these issues. (I will have the same problem
looking for XML handeling in C# too)

Thank you for your help. Other than these problems I have been pretty
shocked at how easy the conversion to C# has been. Kind of fun.

.



Relevant Pages

  • Re: MD5 encryption question - communication with Java
    ... communicates to a Java server. ... Since base64 encoding turns arbitary 3-byte sequences into printable ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: problem when sending data over TCP socke from c# client to jav
    ... so after adding new line char to the end of the string and sending the java ... > Vadym Stetsyak aka Vadmyst ... >> there is no error on the send method, just the java server doesn't get ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: problem when sending data over TCP socke from c# client to jav
    ... there is no error on the send method, just the java server doesn't get thet ... java server gets the sent data. ... > The client is not sending anything at all? ... >> I have a problem when sending data over TCP socket from c# client to java ...
    (microsoft.public.dotnet.languages.csharp)
  • Junior Java Developer position available
    ... Title:Entry / Junior Java Developer ... Develops information systems by designing, developing, and installing ... Uses Java Server Pages to generate dynamic content for delivery to ...
    (comp.lang.java.programmer)
  • J2EE Programmers Needed in RTP, NC
    ... Looking for people with solid J2EE skills. ... Required Qualifications: ... Java Server Pages and Enterprise Java Beans ...
    (comp.lang.java.programmer)