I am at my wits end with Encrytion today, having started off with passwords that apparently do not match to finally closing down onto this issue.
I have a class Function which very simply encrypts a password (no Salt), but when I try to pass a string to the function, i get the error:
"String reference not set to an instance of a String.
Parameter name: s"
If I pass a 'raw' string, ie encrypt("thisword") it works ok, but not if I do encrypt(avariable)
My class is
##################################################
Imports Microsoft.VisualBasic
Imports System.Security.Cryptography
Imports System.Text
Public Class DotShop
Public Function Encrypt(ByVal Password As String) As Byte()
Dim md5Hasher As New MD5CryptoServiceProvider
Dim encrypted As Byte()
Dim encoder As New UTF8Encoding()
encrypted = md5Hasher.ComputeHash(encoder.GetBytes(Password))
Return encrypted
End Function
End Class
##################################################
and the code that calls the calls is
##################################################
Partial Class register
Inherits System.Web.UI.Page
Dim pWord As String
Protected Sub doSomething()
pWord = txtPassword.Text
End Sub
Protected Sub btnFinalSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs)
'blah blah set up the db connection etc
cmdInsert.Parameters.Add("@Password", DotShop.Encrypt(pWord))
'blah blah execute it
End Sub
End Class
##################################################
I found that I caanot simply do Encrypt(txtpassword.text) becuase the textbox is actually in a different panel and for some reason I cannot reference it like so becuase the panel is 'hidden' when the FinalSubmit is clicked. This nenver caused an issue in net1.1 btw, must be some new security feature in 2.0. Anyway, thnkas for taking the time.!


Reply With Quote
Bookmarks