i have a code that select the columns in mysql and fill it in a datagridview...
what i want to do is encrypt the 3 column in the datagridview since it is a password...
can you help me???
here is my code

    Dim dbDataSet As New DataTable
     Dim SDA As New MySqlDataAdapter

        Dim bSource As New BindingSource

        Try
            MySqlConnection.Open()
            Dim query As String
            query = "select * from mcs.login "
            Dim Command As New MySqlCommand(query, MySqlConnection)
            SDA.SelectCommand = Command
            bSource.DataSource = dbDataSet
            DataGridView1.DataSource = bSource
            SDA.Update(dbDataSet)



                MySqlConnection.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally
            MySqlConnection.Dispose()

        End Try

What do you mean by this line

i want to do is encrypt the 3 column in the datagridview since it is a password..

Here is no way for which column you tried to encrypt or which is the password column you thought to encrypt.
You can do it two ways.
1) You can save the encrypted password in the Table when you have created a new user. In this case you would not get any problem to show encrypted data through a DataGridView as you did.

2)After loading data in a DtaGridView you must have to run the encription process for that column in which the password resides through every rows. You can also do it at the time of loading data.

In my opinion, save the encripted password at the time of saving new one, is the best way.

To encryption you always need two value. 1) The Text for encryption and 2) The secret Key value by which the text will be encripted.

I am posting here a simple encription method though there are too many process to encrypt.

Imports System
Imports System.IO
Imports System.Data
Imports System.Data.SqlClient
Imports System.Xml
Imports System.Text
Imports System.Security
Imports System.Security.Cryptography
Imports System.Security.Cryptography.Xml


Public Class UserInstance

    Public Function EncryptUserData(srkey As String, txtkey As String) As String
        Dim SecretFunction As HMACSHA1
        Dim secretKey() As Byte
        Dim hashValue() As Byte
        Dim counter As Integer
        Dim result As String = ""


        secretKey = (New UnicodeEncoding).GetBytes((srkey))

        SecretFunction = New HMACSHA1(secretKey, True)

        hashValue = SecretFunction.ComputeHash((New UnicodeEncoding).GetBytes(txtkey))


        For counter = 0 To hashValue.Length - 1
            result &= Hex(hashValue(counter))
        Next counter


        Return result

    End Function


End Class

You can use it if you like.
Make a loop through the rows of the DataGridView. Call the function to get the encripted password and show the encrypted password in your password column.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.