求助:SQLserver2014 insert数据与查询数据不一致,出现乱码?
请问各位:数据库的数据采样证书加密,下面是创建证书过程;
--创建一个MASTER KEY,秘钥需要MASTER KEY;
CREATE MASTER KEY ENCRYPTION BY PASSWORD='zjh'
GO
--创建证书;
CREATE CERTIFICATE eShopCert WITH SUBJECT ='eShop证书'
GO
--创建由eShopCert证书加密的对称秘钥,对称秘钥名称PwdSymmetric;
CREATE SYMMETRIC KEY PwdSymmetric --创建对称秘钥,名称为PwdSymmetric;
WITH ALGORITHM=AES_256 --加密算法AES_256;
ENCRYPTION BY CERTIFICATE eShopCert --由eShopCert证书加密;
GO
1、首先,通过下面方法向SQLserver2014的表Table1插入加密数据55;
--通过证书eShopCert,打开对称秘钥PwdSymmetric;
OPEN SYMMETRIC KEY PwdSymmetric DECRYPTION BY CERTIFICATE eShopCert
--向表Table1插入id,age_pwd两列,值分别为4和加密后的56;
INSERT Table1(id,age_pwd) VALUES ('13',ENCRYPTBYKEY (KEY_GUID('PwdSymmetric'),'55'))
--关闭对称秘钥;
CLOSE SYMMETRIC KEY PwdSymmetric
2、在通过下面方法,查询加密的数据
--解密数据;
--通过证书eShopCert,打开对称秘钥PwdSymmetric;
OPEN SYMMETRIC KEY PwdSymmetric DECRYPTION BY CERTIFICATE eShopCert
--查看解密后数据;
SELECT *,CONVERT(nvarchar(25),decryptbykey(age_pwd)) FROM Table1
请问,为什么会出现乱码,不是55的值啊?
[此贴子已经被作者于2022-4-6 18:41编辑过]