Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Ok, this has been driving me insane for the last hour!

 

I have the following function:

 

Public Function EncryptPass(ByVal s As String) As String
       Dim encoder As New System.Text.UTF8Encoding
       Dim md5Hasher As New System.Security.Cryptography.MD5CryptoServiceProvider
       Return encoder.GetString(md5Hasher.ComputeHash(encoder.GetBytes(s)))
   End Function

 

To encrypt passwords.

 

However a particular password is returning a null byte after the hash has been replaced. I'm pretty sure this is what is causing my problems.

 

Earlier in an area using an encrypted pass I was getting the following results in the command window:

 

Me.m_Pass.length ==>12

me.m_Pass.toString.length ==>4

!!!!

 

I finally traced it back to the hash returning the null byte which I think is where things are going wrong.

 

Surely someone must have come across this before - any ideas for a solution?

 

Thanks.

 

:)

Please check the Knowledge Base before you post.

"Computers are useless. They can only give you answers." - Pablo Picasso

The Code Net

Posted
Would still be intrigued by replies but have solved it for now by adjusting the db to store binary data rather than strings and then have just assigned the byte array to the field.

Please check the Knowledge Base before you post.

"Computers are useless. They can only give you answers." - Pablo Picasso

The Code Net

  • Administrators
Posted

Try

   Public Function EncryptPass(ByVal s As String) As String
       Dim encoder As New System.Text.UTF8Encoding
       Dim md5Hasher As New System.Security.Cryptography.MD5CryptoServiceProvider

       Return Convert.ToBase64String(md5Hasher.ComputeHash(encoder.GetBytes(s)))
   End Function

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...