注意:密文字段类型为 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;