I'm trying to use a varbinary
parameter with Dapper.NET as follows
string secret = "secret";
// from SELECT ENCRYPTBYPASSPHRASE('secret', N'xx') >>;
string ciphertext = "0x01000000393FE233AE939CA815AB744DDC39667860B3B630C82F36F7";
using (var conn = new SqlConnection(...))
{
var result = conn.ExecuteScalar(@"SELECT CONVERT(NVARCHAR(4000), DECRYPTBYPASSPHRASE(@secret, @ciphertext)) as decrypted",
new
{
secret,
ciphertext = Encoding.Unicode.GetBytes(ciphertext)
});
}
However the result is null
. But it returns a valid result if I run the SQL directly eg.
SELECT CONVERT(NVARCHAR(40), DECRYPTBYPASSPHRASE('secret', 0x01000000393FE233AE939CA815AB744DDC39667860B3B630C82F36F7))
returns xx
which is the encrypted text.
Any idea what I'm doing wrong?