Question

Now I'm not sure if this is something I'm doing wrong, or something thats happening in DynamoDB..

Basically, Im building a simple registration/login system for my project, saving the userdata/password in a DynamoDB instance with the password hashed using RIPEMD160, and salted as well using C#'s RNGCryptoServiceProvider().

Registration seems to work perfectly fine. the issue is upon login, no matter what, the passwords dont match up, and I think its because I'm getting some funky characters back when pulling the hash/salt back from DynamoDB. First off, both the hash and the salt are byte arrays of length 20, and converted to strings before saved in the database.

These examples are copy/pasted from the dynamo web interface

Example Hash: ">�Bb.ŧ�E���d��Ʀ"  
Example Salt: "`���!�!�Hb�m�}e�"

When they're coming back and I debug into the function that pulls back the data from dynamo, both strings have different characters (VS2010 Debugger):

Returned Hash: "u001B>�Bb.ŧ�E��u0003�d�u001C�Ʀ"  
Returned Salt: "`���!u000B�!�Hb�u001Dmu0012�u0001}e�"

Seems these u001B, u000B, u001D, u0012, u0003, u001C, and u0001 are sneaking into the returned data, and I'm not entirely sure whats going on?

Was it helpful?

Solution

You shouldn't be trying to convert opaque binary data into a string in this way in the first place. They're not text so don't treat them that way. You're just begging to lose information that way.

Use Convert.ToBase64String(data) instead of Encoding.GetString before putting the data into the database. When you get it out again, use Convert.FromBase64String to retrieve the original binary data.

Alternatively, don't store the data in a text field to start with - use a database field type which is meant to store binary data...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top