我正在尝试通过密钥加密数据并将其解密。这里是SQL语句的列表:
CREATE CERTIFICATE Shipping04
ENCRYPTION BY PASSWORD = 'pGFD4bb925DGvbd2439587y'
WITH SUBJECT = 'Sammamish Shipping Records',
EXPIRY_DATE = '20201031';
GO
CREATE SYMMETRIC KEY JanainaKey09
WITH ALGORITHM = AES_256
ENCRYPTION BY CERTIFICATE Shipping04;
GO
CREATE TABLE MyTable
(
my_col VARBINARY(68)
)
GO
INSERT INTO MyTable (my_col) VALUES (NULL);
OPEN SYMMETRIC KEY [JanainaKey09]
DECRYPTION BY CERTIFICATE [Shipping04]
WITH PASSWORD = 'pGFD4bb925DGvbd2439587y';
UPDATE MyTable
SET my_col = ENCRYPTBYKEY(KEY_GUID('JanainaKey09'), CONVERT(VARBINARY(8), 0))
一切正常:我得到了一个包含加密数据的表,可以从MyTable
表中选择一个值。但是当我尝试:
OPEN SYMMETRIC KEY [JanainaKey09]
DECRYPTION BY CERTIFICATE [Shipping04]
WITH PASSWORD = 'pGFD4bb925DGvbd2439587y';
SELECT CONVERT(numeric, DECRYPTBYKEY(my_col)) AS balace, *
FROM MyTable;
我遇到错误
SqlState 24000,无效的游标状态
当我替换numeric
-> "BIGINT"
时
'BIGINT'附近的语法不正确:(
怎么了?如何正确解密SQL Server中的值?