Decrypt SQL Server encrypted data from .net

2019-08-14 08:06发布

Is it possible to decrypt the EncryptByCert-encrypted data that is stored in a SQL Server column from within .net?

I want to use EncryptByCert in a stored procedure to store a value RSA-encrpyted in a column. Then a client application will connect to SQL Server and request the encoded data and then needs to decode with the private key of the certificate. Is this possible?

I don't have a profound knowledge of encryption. That's why I ask this question. Maybe there is a good example for doing this?

1条回答
成全新的幸福
2楼-- · 2019-08-14 08:53

SQL Server encrypts the data to a sequence of bytes and returns this as the result. There is no container format used. Therefore, It can directly be decrypted by the RSACryptoServiceProvider. Important to remark here is, that SQL Server uses PKCS #1 V1.5 padding (at least SQL Server 2005).

One thing to notice:
SQL server returns the encrypted result in reverse order as it is desired from RSACryptoServiceProvider. Therefore the byte sequence has to be reversed before decrypting it with RSACryptoServiceProvider.Decrypt.

查看更多
登录 后发表回答