Function MD5Hash(ByVal values As String) As Byte()
Return MD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(values))
End Function
Function Encrypt(ByVal Stringinput As String, ByVal key As String) As String
des.Key = MD5Hash(key)
des.Mode = CipherMode.ECB
Dim buffer As Byte() = ASCIIEncoding.ASCII.GetBytes(Stringinput)
Return Convert.ToBase64String(des.CreateEncryptor().TransformFinalBlock(buffer, 0, buffer.Length))
End Function
Private Sub btnSignup_Click(sender As Object, e As EventArgs) Handles btnSignup.Click
Using con As New SQLiteConnection(ConnectionString.ToString)
Dim query As String = "INSERT INTO LoginTB (user, password) VALUES (@username,@password)"
con.Open()
Using cmd As New SQLiteCommand(query, con)
cmd.Parameters.AddWithValue("@username", TxtBxUsername.Text)
cmd.Parameters.AddWithValue("@password", Encrypt(TxtBxPassword.Text, "abc"))
cmd.ExecuteNonQuery()
MsgBox("user created successfully")
con.Close()
End Using
End Using
End Sub
当我单击注册按钮时,错误出现在MD5Hash的值中。
System.NullReferenceException'对象引用未设置为对象的实例。'
我知道有人问过很多。但是我找不到解决这个问题的方法。
答案 0 :(得分:0)
可能由于未为MD5创建实例而引起的问题。您可以尝试如下更改功能MD5Hash
的代码吗?
Function MD5Hash(ByVal values As String) As Byte()
Static hash As MD5 = MD5.Create()
Return hash.ComputeHash(ASCIIEncoding.ASCII.GetBytes(values))
End Function