473,410 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,410 software developers and data experts.

Java To C# String Conversion Problem...

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.
Jul 20 '06 #1
0 3228

Sign in to post your reply or Sign up for a free account.

Similar topics

73
by: RobertMaas | last post by:
After many years of using LISP, I'm taking a class in Java and finding the two roughly comparable in some ways and very different in other ways. Each has a decent size library of useful utilities...
0
by: Christophe Elek | last post by:
Ok, I am completly at lost :) in both cases (my Yenc and zip utilities) i try to do the following 1) get a String 2) transform in byte 3) so some computation (either adding value to the byte...
36
by: Robert Baer | last post by:
I used Google and found some references for integer in Java. But "int" not only does not work, it also prevents reading X and Y coordinates of the mouse. What i would like to do: 1) Get X and Y...
3
by: AHanso | last post by:
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...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
12
by: steven acer | last post by:
hello, i have a java app that constructs an xml from a specific file format and vice versa. i've been asked to convert it to c++, but im not an expert in c++, actually im mere beginner you can...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
3
by: kr151080 | last post by:
I need some help with a Measurement Program I Wrote.....I have this code as the main workings of my program: import java.util.*; public class Measurement{ { static Scanner console = new...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.