Decrypt SQL Server encrypted data from .net

半城伤御伤魂 提交于 2019-12-13 00:59:16

问题


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:


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.



来源:https://stackoverflow.com/questions/7917692/decrypt-sql-server-encrypted-data-from-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!