1

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
  • I'm quite sure that this decryption is possible, but I didn't find which format is used by EncryptByCert. Commented Oct 29, 2011 at 13:28

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.