注意:密文字段类型为 nvarchar

CREATE SYMMETRIC KEY dcmy
WITH ALGORITHM = DES
ENCRYPTION BY PASSWORD = '1234567890'

--打开对称密钥
OPEN SYMMETRIC KEY dcmy DECRYPTION BY PASSWORD = '1234567890'


--以加密的方式存放数据
INSERT INTO [tt22] (aa) VALUES
(
EncryptByKey(Key_GUID('dcmy'), '456456')
)

select * from [tt22]
/*
TeaName TeaPwd
-------------------- -----------------
老师五 ⤀菮䰣劦洼ꒅ䉜 ᎍ視쥬娺簍뾼쒽ԍꑇ
*/
select CONVERT(varchar, DecryptByKey(aa)) from [tt22]
/*
456456
*/

 

CLOSE SYMMETRIC KEY dcmy;
DROP SYMMETRIC KEY dcmy;

posted on 2020-11-30 16:06  御不凡  阅读(217)  评论(0编辑  收藏  举报