2014-10-05 186 views
0

我的「MySQL連接」是完全在ASP.NET獲取AES_DECRYPT值從ASP.NET網頁「MySQL的」

工作

我可以在數據庫中插入值完全

的問題時,當我想從下表得到一個密碼值

The Table has columns as, 
ID->Integer 
name->Varchar 
mobile_no->VarChar 
password->blob 

Password column gives me problem 

    MySqlCommand cmd2=new MySqlCommand("SELECT AES_DECRYPT(password,'qwerty') FROM mytable1 where [email protected]", connection); 

    cmd2.Parameters.AddWithValue("@z2", TextBox1.Text); 

    String pass = cmd2.ExecuteScalar().ToString(); 


The 3rd line is giving me problem. 

I want to compare this "pass" with ""Textbox2.text"" 

OR 

I want to display that password on webpage (just fro try) 

i.e., ""Label1.text=pass"" 

Its displaying this on Label...... ""System.Byte[] "" 

回答

0

嘗試這樣的:

MySqlCommand cmd2=new MySqlCommand("SELECT AES_DECRYPT(password,'qwerty') FROM mytable1 where [email protected]", connection); 

    cmd2.Parameters.AddWithValue("@z2", TextBox1.Text); 

     //prepare adapter to run query 
     adapter = new MySqlDataAdapter(cmd2); 
     DataTable Dt = new DataTable(); 
     //get query results in DataTable 
     adapter.Fill(Dt); 
string pass = Dt.Rows[0][0].ToString(); 
    // your password contains Byte array as You said it is showing System.Byte[] 
//You should convert it /Decode it into proper Plain text 

編輯 取決於你的編碼,你可以嘗試這樣的

string result = System.Text.Encoding.Default.GetString(pass); 

string result = System.Text.Encoding.UTF8.GetString(pass); 

//dispaly result on label 
+0

我創建的每個所需的連接,適配器和其他一切需要.... 我剛纔把我的代碼總之.... 但如果我按照精確的代碼......然後還.... 「通行證」將包含「System.Byte []」,而不是現在更新原有passowrd – 2014-10-05 13:23:09

+0

嘗試 – 2014-10-05 13:26:53

+0

確定讓我來試試 給我5分鐘 – 2014-10-05 13:29:15