Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. SQLite encryption types for data

SQLite encryption types for data

Scheduled Pinned Locked Moved C#
databasehelpcsharpsqlitesecurity
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DPaul1994
    wrote on last edited by
    #1

    I have an application in C# which uses a SQLite database. In this database I have a table where I inserted a value encrypted with sha1, via sql query. Te problem is that I want to select that data and use it like:

    cmd.CommandText = "Select * from accounts where (username=@username and password=sha1(@password));";
    cmd.Parameters.AddWithValue("@password", password);

    OR

    cmd.CommandText = "Select * from accounts where (username=@username and password=@password);";
    cmd.Parameters.AddWithValue("@password", sha1(password));

    But from what I heard, I can't use sha1 like this, I have to use a function like this one, but it doesn't work:

    string sha1(string password) {
    byte[] byteArray = Encoding.UTF8.GetBytes(password);
    return Convert.ToBase64String(sha1.ComputeHash(byteArray);
    }

    I receive error:

    sha1(string) is a method, which is not valid in the given context

    The other thing, I heard about KDF ( key definition function) which it seems to be a better encryption type but I don't really know how to use it. Can anybody help me with that?

    L Richard DeemingR 2 Replies Last reply
    0
    • D DPaul1994

      I have an application in C# which uses a SQLite database. In this database I have a table where I inserted a value encrypted with sha1, via sql query. Te problem is that I want to select that data and use it like:

      cmd.CommandText = "Select * from accounts where (username=@username and password=sha1(@password));";
      cmd.Parameters.AddWithValue("@password", password);

      OR

      cmd.CommandText = "Select * from accounts where (username=@username and password=@password);";
      cmd.Parameters.AddWithValue("@password", sha1(password));

      But from what I heard, I can't use sha1 like this, I have to use a function like this one, but it doesn't work:

      string sha1(string password) {
      byte[] byteArray = Encoding.UTF8.GetBytes(password);
      return Convert.ToBase64String(sha1.ComputeHash(byteArray);
      }

      I receive error:

      sha1(string) is a method, which is not valid in the given context

      The other thing, I heard about KDF ( key definition function) which it seems to be a better encryption type but I don't really know how to use it. Can anybody help me with that?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      See Secure Password Authentication Explained Simply[^]. You need to show some more of your code, to show why the context is incorrect as you have coded it. Where exactly does the error message appear?

      L D 2 Replies Last reply
      0
      • L Lost User

        See Secure Password Authentication Explained Simply[^]. You need to show some more of your code, to show why the context is incorrect as you have coded it. Where exactly does the error message appear?

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Note he wrote "encryption" but meant "hashing" (sha1). I can't help him with that regarding SQLite but maybe you can add something to your answer.

        Recursion: see Recursion.

        1 Reply Last reply
        0
        • L Lost User

          See Secure Password Authentication Explained Simply[^]. You need to show some more of your code, to show why the context is incorrect as you have coded it. Where exactly does the error message appear?

          D Offline
          D Offline
          DPaul1994
          wrote on last edited by
          #4

          It's ok, I want to use KDF instead, but I don't get anything of that code..I solve it with sha1..

          1 Reply Last reply
          0
          • D DPaul1994

            I have an application in C# which uses a SQLite database. In this database I have a table where I inserted a value encrypted with sha1, via sql query. Te problem is that I want to select that data and use it like:

            cmd.CommandText = "Select * from accounts where (username=@username and password=sha1(@password));";
            cmd.Parameters.AddWithValue("@password", password);

            OR

            cmd.CommandText = "Select * from accounts where (username=@username and password=@password);";
            cmd.Parameters.AddWithValue("@password", sha1(password));

            But from what I heard, I can't use sha1 like this, I have to use a function like this one, but it doesn't work:

            string sha1(string password) {
            byte[] byteArray = Encoding.UTF8.GetBytes(password);
            return Convert.ToBase64String(sha1.ComputeHash(byteArray);
            }

            I receive error:

            sha1(string) is a method, which is not valid in the given context

            The other thing, I heard about KDF ( key definition function) which it seems to be a better encryption type but I don't really know how to use it. Can anybody help me with that?

            Richard DeemingR Offline
            Richard DeemingR Offline
            Richard Deeming
            wrote on last edited by
            #5

            Hashing a password without using a unique salt for each record is a very bad idea. Troy Hunt: Our password hashing has no clothes [^] Salted Password Hashing - Doing it Right[^]


            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups