We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,031 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

How to decrypt data from SQL Server??? Help Please...

Hello people. Im having a problem in my coding. I am doing a username and password application (sumtthing like a password keeper). So I have created the interface and i integrated vb 2008 with sql server 2008. So the adding of account and password all went fine. I have applied aes 128 bits for the password. that means when the user enters a new record for example an email and he click save, the password will automatically be encrypted before it is saved in the database. now im having a problem where when i want to display the password in the gridview of vb.net (i decided to use grid view to show all the username and password), i am having trouble in decrypting the password column to show the real password to the user. of course user cant decrypt the password using their brains. so I want to know how to choose dat particular column (password column) and decrypt it before it appears in the gridview. bcoz now it is appearing gibberish i.e. aes 128 bits. Please help me. Below i show u some snippet of my codes in encrypting and storing it in the database.

Private Sub btnemailAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnemailAdd.Click

        If txtEmailName.Text <> "" And txtEmailDesc.Text <> "" And txtEmailUsrname.Text <> "" And txtEmailPass.Text <> "" Then

            Dim ciphertext As String
            ciphertext = Encrypt(txtEmailPass.Text)
            txtEncrypt.Text = ciphertext


            'Dim NetStream As NetworkStream = TCPClient.GetStream()
            'Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(Encrypt(txtEmailPass.Text))
            'NetStream.Write(sendBytes, 0, sendBytes.Length)


            'Dim sequelAdapterReg As New SqlDataAdapter()
            sequelDataAdapter.InsertCommand = New SqlCommand("INSERT INTO EMAILinfo VALUES(@EmailName, @EmailDescription, @EmailUsername, @EmailPassword)", sequelConnectionReg)
            sequelDataAdapter.InsertCommand.Parameters.Add("@EmailName", SqlDbType.VarChar).Value = txtEmailName.Text
            sequelDataAdapter.InsertCommand.Parameters.Add("@EmailDescription", SqlDbType.VarChar).Value = txtEmailDesc.Text
            sequelDataAdapter.InsertCommand.Parameters.Add("@EmailUsername", SqlDbType.VarChar).Value = txtEmailUsrname.Text
            sequelDataAdapter.InsertCommand.Parameters.Add("@EmailPassword", SqlDbType.VarChar).Value = txtEncrypt.Text

            sequelConnectionReg.Open()
            sequelDataAdapter.InsertCommand.ExecuteNonQuery()
            sequelConnectionReg.Close()

            MsgBox("Email Has Been Successfully Added!", MsgBoxStyle.Information)

            Me.Close()

            sequelDataSet.Clear()

            sequelDataAdapter.Fill(sequelDataSet)

            InterfaceMain.emailDataGrid.DataSource = sequelDataSet.Tables(0)

            InterfaceMain.Enabled = True

the code above is how i encrypt and store it in the databse. kindly help me how to decrypt it. it would be a real help for me. thanks folks... :)

2
Contributors
3
Replies
2 Days
Discussion Span
1 Year Ago
Last Updated
4
Views
Question
Answered
Bheeman89
Light Poster
36 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

ciphertext = Encrypt(txtEmailPass.Text)

Wich encrypt function are you using? Is written by your self? or is some of the predefined System.Security.Cryptography? Which one?

Did you already read this?

Let us know

lolafuertes
Practically a Posting Shark
889 posts since Oct 2008
Reputation Points: 164
Solved Threads: 189
Skill Endorsements: 5

hi lola... actually its a predefined. i used the System.Security.Cryptography. Yeah I saw the example u gave me and i have the exact one..I have the code on how to decrypt actually, but i dunno how to apply it to that password column only and decrypt the whole databases password. :) any ideas?

Bheeman89
Light Poster
36 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

You need to read each row in the table, then decrypt the password field.

You can do it by using a data adapter to fill a datatable, then using a foreach loop analyze each row in the datatable, decrypt the password and update the datatable row.

Finally, use the datatable as datasource for your datagrid.

Hope this helps

lolafuertes
Practically a Posting Shark
889 posts since Oct 2008
Reputation Points: 164
Solved Threads: 189
Skill Endorsements: 5
Question Answered as of 10 Months Ago by lolafuertes

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0655 seconds using 2.68MB