I am able to encrypt password using AES_ENCRYPT in VB.NET 2010 and MySQL, but while trying to retrieve the encrypted password into a textbox using AES_DECRYPT it is showing null.
Please anyone can help me with the missing code.
My code is....
What I have tried:
encryption code:
sql.CommandText = "INSERT INTO users(uid,uname,urole,upwd,mob)VALUES('" & Me.lblUID.Text & "','" & Me.txtUser.Text & "','" & Me.cmbRole.SelectedValue & "', AES_ENCRYPT('" & pwd & "','" & ed & "'),'" & Me.txtPwd.Text & "')"
decryption code which I tried:
comm.CommandText = "SELECT uname,uid,urole FROM users WHERE uid= '" & Trim(Me.txtUID.Text) & "' AND upwd= '" & AES_DECRYPT(Me.txtPwd.Text) & "' "
DECRYPT FUNCTION:
Dim cipherBytes As Byte() = Convert.FromBase64String(cipherText)
Using encryptor As Aes = Aes.Create()
Dim pdb As New Rfc2898DeriveBytes(EncryptionKey, New Byte() {&H49, &H76, &H61, &H6E, &H20, &H4D, _
&H65, &H64, &H76, &H65, &H64, &H65, _
&H76})
encryptor.Key = pdb.GetBytes(32)
encryptor.IV = pdb.GetBytes(16)
Using ms As New MemoryStream()
Using cs As New CryptoStream(ms, encryptor.CreateDecryptor(), CryptoStreamMode.Write)
cs.Write(cipherBytes, 0, cipherBytes.Length)
cs.Close()
End Using
cipherText = Encoding.Unicode.GetString(ms.ToArray())
End Using
End Using
Return cipherText