1,创建测试表
CREATE TABLE TBLUser
(
Name nvarchar(30),
Password varbinary(1000)
)
CREATE master key ENCRYPTION BY PASSWORD ='passW@ord'
CREATE CERTIFICATE TestCert with SUBJECT = 'Test Certificate'
CREATE SYMMETRIC KEY TestSymmetric WITH ALGORITHM = AES_256 ENCRYPTION BY CERTIFICATE TestCert
OPEN SYMMETRIC KEY TestSymmetric DECRYPTION BY CERTIFICATE TestCert;
INSERT INTO TBLUser values('张三', ENCRYPTBYKEY(Key_Guid(N'TestSymmetric'), '123456'));
CLOSE SYMMETRIC KEY TestSymmetric;
SELECT * FROM TBLUser7.解密数据
OPEN SYMMETRIC KEY TestSymmetric DECRYPTION BY CERTIFICATE TestCert;
SELECT Name, CAST(DecryptByKey(password) as varchar(100)) Password FROM TBLUser;
CLOSE SYMMETRIC KEY TestSymmetric;
- 本文标题: 数据库加密
- 文章分类:【SQLServer】
- 非特殊说明,本文版权归【胡同里的砖头】个人博客 所有,转载请注明出处.