Bizarre SHA result in DBhttp://forums.asp.net/t/334620.aspx/1?Bizarre+SHA+result+in+DBThu, 11 Sep 2003 21:06:59 -0400334620334620http://forums.asp.net/p/334620/334620.aspx/1?Bizarre+SHA+result+in+DBBizarre SHA result in DB I am encypting a password to SHA with the following code but the value stored in DB is odd For passord 'pass' i get this stored in DB(datatype nvarchar) : N&#30;#=[rpF)c4[W=nf&#4; <pre class="prettyprint">Public Shared Function sha_pass(ByVal pass As String) As String Dim AE As New ASCIIEncoding() Dim ClearTextData() As Byte = AE.GetBytes(pass) Dim SHA1Data() As Byte Dim sha As New SHA1CryptoServiceProvider() SHA1Data = sha.ComputeHash(ClearTextData) Return AE.GetString(SHA1Data) End Function 'function call pass1 = sha_pass(Request.Form(&quot;pass&quot;).ToString())</pre> What is the problem? 2003-09-10T07:06:37-04:00336498http://forums.asp.net/p/334620/336498.aspx/1?Re+Bizarre+SHA+result+in+DBRe: Bizarre SHA result in DB I think you're converting an array of arbitrary binary bytes (8 bits) into a string using ASCII encoding (7 bits). You might want to consider converting the binary array to Base64 format (or similar) instead and storing that. This would be something like: <pre class="prettyprint">SHA1Data = sha.ComputeHash(ClearTextData) Return Convert.ToBase64String(SHA1Data)</pre> And you can convert it back into a byte array if need be using Convert.FromBase64String(). This will give you an ASCII safe string. The BitConverter class is another (longer output) way to do the same thing. Alternatively, you might consider storing the byte array itself instead of converting to a string. Thanks, Erik 2003-09-11T21:06:59-04:00