Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 650
hbeam Avatar asked Nov 29 '12 02:11

hbeam


1 Answers

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

like image 90
Bjorg P Avatar answered Oct 14 '22 07:10

Bjorg P