A
AHanso
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.
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.