I have a PostgreSQL database where I use the pgp_sym_encrypt()
function to crypt data
INSERT INTO public.product(name, brand, size, price)
VALUES (pgp_sym_encrypt('product1', 'AES_KEY'), 'brand 1', 1, 1);
And it works with pgp_sym_decrypt()
SELECT pgp_sym_decrypt(name::bytea, 'AES_KEY') FROM public.product;
Is there some equivalent code in c# to decrypt the data which are crypted with the pgp_sym_encrypt()
function ?
I tried this kind of code but I always get the crypted data
using (Aes aes = Aes.Create())
{
aes.Key = Encoding.UTF8.GetBytes("AES_KEY");
aes.IV = new byte[16];
ICryptoTransform decryptor = aes.CreateDecryptor(aes.Key, aes.IV);
var buffer = Encoding.UTF8.GetBytes(data);
using (MemoryStream memoryStream = new MemoryStream(buffer))
{
using (CryptoStream cryptoStream = new CryptoStream((Stream)memoryStream, decryptor, CryptoStreamMode.Read))
{
using (StreamReader streamReader = new StreamReader((Stream)cryptoStream))
{
return streamReader.ReadToEnd();
}
}
}
}