I wnat to create a C# class to decrypt a byte array encrypted using T-SQL's EncryptByPassPhrase. (Yes, I know I could decrypt within SQL Server, but what I need is to be able to encrypt/decrypt within both the database tier and in the middle tier equivalently.)
I understand that SQL Server's EncryptByPassPhrase and DecryptByPassPhrase use the TripleDES symmetric key algorithm. It's not clear to me, though, what the IV should to simulate SQL Server's cryptology. I can encrypt/decrypt using the TripleDESCryptoServiceProvider class, but I can't find the correct implementation of key and IV to replicate what SQL Server is doing.
Has anyone done something similar? Thanks!
There is a public repo on github that recreates EncryptByPassPhrase
in C# and the IV depends on the version of SQL Server as the implementation changed. You can check out the repo for the code. https://github.com/krcs/SQLServerCrypto
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With