5
CREATE ASYMMETRIC KEY Asym_EPassword  
WITH ALGORITHM = RSA_512 
ENCRYPTION BY PASSWORD = testdemo123

我已经Password用上面的加密非对称密钥加密了我的表的一列。

现在我想解密查询中的passwordselect

谁能建议如何做到这一点?

4

1 回答 1

1
SELECT CONVERT(NVARCHAR(100), 
    DecryptByAsymKey(AsymKey_ID('Asym_EPassword'),
    YourColumn, 'testdemo123')) AS PlainText
FROM YourTable;

SQLFiddle don't let users create asymmetric keys, so for demo copy/paste this to your own SSMS:

CREATE ASYMMETRIC KEY Asym_EPassword
WITH ALGORITHM = RSA_512 
ENCRYPTION BY PASSWORD = 'testDemo123!'

DECLARE @PlainText NVARCHAR(100)
DECLARE @CipherText VARBINARY(MAX)

SET @PlainText = 'AAAAA'
SELECT @CipherText = EncryptByAsymKey(AsymKey_ID('Asym_EPassword'), @PlainText);

SELECT @CipherText;

SELECT CONVERT(NVARCHAR(100), DecryptByAsymKey(AsymKey_ID('Asym_EPassword'), @CipherText, N'testDemo123!'));
于 2013-06-28T08:43:28.737 回答