Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQLite encryption hashing with SHA1 or KDF

Status
Not open for further replies.

DPaul1994

Programmer
Mar 9, 2015
46
RO
Hi everyone. I have an application which uses a SQLite database. In database, I have a table and in one column, I have a value inserted from SQL code which is encrypted with sha1. But, I want to use it in my C# application like this:
Code:
cmd.CommandText = "Select * from accounts where (username=@username and password=sha1(@password));";
cmd.Parameters.AddWithValue("@password", password);

OR

Code:
cmd.CommandText = "Select * from accounts where (username=@username and password=@password);";
cmd.Parameters.AddWithValue("@password", sha1(password));
But, I understand that I can't use sha1 in SQLite, because it doesn't exists any library for that. But, exists a function that help like this one:
Code:
string sha1(string input) {
            byte[] byteArray = Encoding.UTF8.GetBytes(input);
            return Convert.ToBase64String(sha1.ComputeHash(byteArray);
        }
But is not working, I get error at
Code:
sha1.ComputeHash(byteArray);
Error code:
Code:
sha1(stirng) is a method,which is not valid in the given context
So, I looked for other solution and I found KDF, but I don't really understand how to use it. Can anybody help me with that? It's fine also if manage to encrypt it with sha1.
 
Oups, my mistake, code tag with name doesn't work guys
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top