how to use DES_DECRYPT() function to get data from mysql?
At last i try Encryption and Compression Functions in mysql for secure password and username.
DES_ENCRYPT function is perfectly work for encrypt. I give the code which i use to encrypt and save in database.
MySqlConnection connection = new MySqlConnection(MyConString); MySqlCommand command = connection.CreateCommand(); command.CommandText = "insert into user (User_Id, Password, Branch, Upto_Date) values (DES_ENCRYPT('" + textBox1.Text + "'),DES_ENCRYPT('" + textBox2.Text + "'),'" + comboBox1.SelectedItem.ToString() + "','" + textBox4.Text + "') "; connection.Open(); command.ExecuteNonQuery(); MessageBox.Show("Record Succesfully Added", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); connection.Close();
But i have trouble to retrieve data in DES_DECRYPT function.
"select DES_DECRYPT(User_Id),DES_DECRYPT(Password),Branch,Upto_Date from user" code to retrieve but no use,. What i do for get the data from mysql datatable?.
the last record is inserted using DES_ENCRYPT() function.
DES_DECRYPT is the way to decrypt
Lets stick to the SQL part of it. Easy example:
/* generating test table */ CREATE TABLE `test` ( `testField` varchar(512) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1 /* adding some test data to it */ INSERT INTO test () VALUES (DES_ENCRYPT("Hello")), (DES_ENCRYPT("World"));
Now to find out how it does look encrypted...
SELECT testField FROM test; +-------------+ | testField | +-------------+ | €p!˜*D°k | | €ü«ü€D»Ûë | +-------------+
...and decrypt it!
SELECT DES_DECRYPT(testField) FROM test; +-------------+ | testField | +-------------+ | Hello | | World | +-------------+
Basically, if you decrypt it this way as you've described it, the database should return the plain text.
- Try to start with figuring this out on the SQL side first (phpmyadmin, SQLyog, there are plenty of tools to directly work on the MySQL database).
- If this is working, move to your .NET program to finish this.
Another note, if you use this kind of password protection, a clear password is used between your application and the database server. Even if this connection might be SSL-"protected", I'd advise to not do it this way. It usually is safer to use Hash-Algorithms (like SHA512) for this purpose and just store the Hashes in your database to avoid clear passwords at all.
- A Linux, Apache, MySQL, PHP (LAMP) stack is a combination of open source software that is typically installed together to enable a server to host dynamic […]
- MySQL is an the most popular open-source database management system, in most of hosting company its has been bundle by LAMP(Linux, Apache, MySQL, PHP/Python/Perl) stack. Another alternative […]
- MySQL is the world’s most popular open-source database. Despite its powerful features, MySQL is simple to set up and easy to use. Below are some instructions […]