SQL DES数据加密 解密问题!急急急,求各位大虾帮帮忙! 10
我对SQL2005数据库中的某些字段加密并将加必的密文放在"miwen",但我对其进行解密,将解密结果放在列"mingwen",待代码成功执行完毕之后,做SELECT查询...
我对SQL 2005数据库中的某些字段加密并将加必的密文放在"miwen",但我对其进行解密,将解密结果放在列"mingwen",待代码成功执行完毕之后,做SELECT查询,发现,"mingwen" 里面的居然是空的,小弟试了N多方法,均不得其法,求各位大虾帮小弟,小弟不胜感激!!!!
代码如下:
CREATE SYMMETRIC KEY key1 WITH ALGORITHM=DES ENCRYPTION BY PASSWORD='123456'GOOPEN SYMMETRIC KEY key1 DECRYPTION BY PASSWORD='123456' update table1 set miwen=CAST(DECRYPTBYKEY(mingwen) AS varchar(1000))
CLOSE SYMMETRIC KEY key1GODROP SYMMETRIC KEY key1GO
其中miwen字段类型为二进制,mingeen字段类型为varchar(8000) 展开
代码如下:
CREATE SYMMETRIC KEY key1 WITH ALGORITHM=DES ENCRYPTION BY PASSWORD='123456'GOOPEN SYMMETRIC KEY key1 DECRYPTION BY PASSWORD='123456' update table1 set miwen=CAST(DECRYPTBYKEY(mingwen) AS varchar(1000))
CLOSE SYMMETRIC KEY key1GODROP SYMMETRIC KEY key1GO
其中miwen字段类型为二进制,mingeen字段类型为varchar(8000) 展开
1个回答
展开全部
下面是我在SQL 2008 R2中调试成功的语句,已对关键语句做了备注,其它的看不懂的,百度一下吧。
--建立对称密钥
--CREATE SYMMETRIC KEY key1 WITH ALGORITHM=DES ENCRYPTION BY PASSWORD='123456'
OPEN SYMMETRIC KEY key1
DECRYPTION BY PASSWORD='123456' --必须与原设定口令一样
DECLARE @str NVARCHAR(100),@Encrypted VARBINARY(MAX),@DEEncrypted varchar(8000)
SET @str=N'AABBCC' --要加密的字符串
SELECT @Encrypted=ENCRYPTBYKEY(KEY_GUID('key1'),@str)
SELECT @DEEncrypted=CAST(DECRYPTBYKEY(@Encrypted) AS NVARCHAR(100))
SELECT '加密'=@Encrypted ,'解密'=@DEEncrypted --显示加密与解密结果
UPDATE [_TABLE1] SET mingwen = @Encrypted,mingeen = @DEEncrypted
CLOSE SYMMETRIC KEY key1
--删除对称密钥
--DROP SYMMETRIC KEY key1
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询