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#=[rpF)c4[W=nf
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("pass").ToString())
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:
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
This posting is provided "AS IS" with no warranties, and confers no rights.
Moguay
Member
10 Points
2 Posts
Bizarre SHA result in DB
Sep 10, 2003 07:06 AM|LINK
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("pass").ToString())What is the problem?ErikOls
Member
55 Points
11 Posts
Microsoft
Re: Bizarre SHA result in DB
Sep 11, 2003 09:06 PM|LINK