views:

330

answers:

3

Hello, I'm looking for help to convert an ASCII MD5 hashed password into a Unicode MD5 hashed password?

For example, I'll use the string "password" .

When it's converted to an ascii byte array, I get a base64 encoded hash of X03MO1qnZdYdgyfeuILPmQ== When it's converted into a unicode byte array, I get a base64 encoded hash of sIHb6F4ew//D1OfQInQAzQ==

All my passwords are stored in an md5 hash that was applied to an ascii byte array, but I'm trying to migrate my application's user data to a system that stores password in an md5 hash that is applied a unicode byte array.

In case it's not clear, with the following C#code:

var passwordBytes = Encoding.ASCII.GetBytes("password");
var hashAlgorithm = HashAlgorithm.Create("MD5");
var hashBytes = hashAlgorithm.ComputeHash(passwordBytes);

My current system uses this, but the system I'm moving to has a different first line. It uses Encoding.Unicode.GetBytes.

Does anybody know how I can convert my passwords? From

X03MO1qnZdYdgyfeuILPmQ==

into

sIHb6F4ew//D1OfQInQAzQ==

I'm guessing the answer is that I can't.. the encoding is being done before the hashing, but I thought I'd inquire the bright minds of stackoverflow and see if anybody has a way.

+3  A: 

No, you can't. md5 is a one way operation, you can't deduct anything out of the hash concering the original string.

Femaref
A: 

This doesn't answer your question directly, but one solution to the problem you're having (the migration) is to convert entered passwords into an ascii byte array before hashing with the new system. This is a bit of a hack, but it should work. might work depending on the specifics of your situation.

Cam
+8  A: 

Can you use UTF-8? If so, it solves your problem as Unicode encoded in UTF-8 and ASCII would have the same MD5 hash. (Assuming that when you refer to ASCII you are referring to the lower seven bits).

Alternatively, you could create a unicode hash, check if that works, and if it doesn't try an ASCII hash.