-2

I want to get the value of the Encrypted password into a string variable. but I am getting the whole query.

Here is my code:-

string strpassword = "select  sys.get_enc_val ('" + txtpassword.Text + "', 'F20FA982B4C2C675')  from dual";
    Response.Write(strpassword);

In strpassword i get the whole query.

But in Toad the result is as

F52377D5FFB1A47F

how to get that in oracle?

Nad
  • 4,605
  • 11
  • 71
  • 160

1 Answers1

3

When you write

string strpassword = "select  sys.get_enc_val ('" + txtpassword.Text + "', 'F20FA982B4C2C675')  from dual";
Response.Write(strpassword);

Then you are simply displaying the string value as you are not executing the SQL which is present inside the string.

What you are looking for is the result of the SQL which is present inside the string. To get the result of the SQL stored inside the string you need to execute it.

You can try like this:

string queryString = "select  sys.get_enc_val ('" + txtpassword.Text + "', 'F20FA982B4C2C675')  from dual";
    using (SqlConnection connection = new SqlConnection(connectionString))
    {
        SqlCommand command = new SqlCommand(queryString, connection);
        connection.Open();
        SqlDataReader reader = command.ExecuteReader();
        try
        {
            while (reader.Read())
            {
                Console.WriteLine(String.Format("{0}",reader[0]));
            }
        }
        finally
        {
            reader.Close();
        }
    }

As commented above, your query is prone to SQL Injection. A better way is to use paramterized query to get rid of it. Something like

string sql = "select  sys.get_enc_val (@myvar) from dual";
SqlConnection connection = new SqlConnection(/* connection info */);
SqlCommand command = new SqlCommand(sql, connection);

command.Parameters.AddWithValue("myvar", txtpassword.Text);
Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331