What I want is to send encypted data from my app to PostgreSQL database via formatted string (query) by using Npgsql. Problem is that after sha256.ComputeHash() I get byte array which I’m trying to send by inserting it into my string query. It works fine but then in my dbms column I see System.Byte[] instead of byte array. How can I fix that?
My string query is something like that:
private readonly SHA256 sha256 = SHA256.Create();
string sql = $"""
INSERT INT table(encrypted_column) VALUES (
'{sha256.ComputeHash(data)}');
""";
```[What in db after Query][1]
[1]: https://i.stack.imgur.com/9Ch7t.png
2
Answers
So using a formatted string was a bad idea. Thanks to SNBS better way is to use parameters: https://www.npgsql.org/doc/basic-usage.html
SHA256.ComputeHash()
returns a byte array. It is converted to a string implicitly, usingToString()
. And it just returns the type string for byte array. You should use this query: