Having difficulty trying to get this code in .NET (C#) to print out this string EXACTLY as it prints out within Java using a) the MD5 hashing algorithm and B). In Java here's how a string "ididnot" would print out
E#øðûÜ+œ_Z*º~
And here's the Java code
string pswd;
public String getPswd() {return pswd;}
public void setPassword(String passwd) {
MessageDigest sha = MessageDigest.getInstance("MD5");
byte[] tmp = passwd.getBytes ();
sha.update(tmp);
pswd = new String( sha.digest());
}
public static void main( String [] args )
{
Encrypt e = new Encrypt();
String psswd1 = "ididnot";
e.setPassword( psswd1) ;
System.out.println("Password: " + pwd + " ==> " + e.getPassword());
}
In C# I'm just coming ooh soo close in achieving the same exact string (due to it being within the SQL database) and this is the closest I can come to getting that EXACT hashed string for "ididnot" to work
public static string EncryptPasswordAsText(string message)
{
MD5 md5 = MD5.Create();
UTF7Encoding nd = new UTF7Encoding();
byte[] data = nd.GetBytes(message);
byte[] digest = md5.ComputeHash(data);
string returndat = nd.GetString(digest);
return returndat;
}
Yet I notice that C# cares about encoding and in this example I'm using UTF-7 encoding which is one of the two closest possibilities to get an exact match thus far which gives me the string E#øðûÜ_Z*º~ and when using ASCII I'm able to achieve getting the string E#øðûÜ+œ_Z*º~ which while the later comes much closer to the goal string of E#øðûÜ+œ_Z*º~ it's no match in the end of the day. Thus I'm now frusterated in the slight subtle differences of Java and .NET and wonder how can this can be achieved. Would this have anything to do with the fact that bytes in .NET are unsigned by default while being signed in Java? Or perhaps just finding that perfect encoding type? The closest I could come up with was getting a string "12345" encode to come up exactly as it does within the database with "Windows-1252" encoding, but everything else isn't turning up a match.
Any help would be greatly appeciated.