hbeam
hbeam

Reputation: 187

Replicate T-SQL DecryptByPassPhrase in C#

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!

Upvotes: 9

Views: 5986

Answers (1)

Bjorg P
Bjorg P

Reputation: 1073

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

Upvotes: 1

Related Questions