5
我想加密和解密表中的一列。我的代碼是這樣的:奇怪的結果從DecryptByPassphrase
drop table EncryptString
go
create table EncryptString(db int, String varchar(100))
go
insert into EncryptString values (2, '123456789')
go
ALTER TABLE EncryptString
ADD StringEncrypted varbinary(256);
GO
declare @Pass nvarchar(512)
set @Pass = 'somepassword'
update EncryptString set StringEncrypted = ENCRYPTBYPASSPHRASE(@Pass, String, 1, convert(varbinary(128), db))
where db = 2
select * From EncryptString
SELECT db, StringEncrypted
AS 'Encrypted String', CONVERT(nvarchar,
DecryptByPassphrase('somepassword', StringEncrypted, 1
, CONVERT(varbinary, db)))
AS 'Decrypted String' FROM EncryptString
WHERE db = 2;
爲什麼我的 '解密的字符串' 是這樣的: ㈱㐳㘵㠷9
感謝
這很有效。謝謝我不知道如何將問題標記爲已回答??? – user1212016 2012-03-21 15:17:57
@ user1212016 - 您可以勾選答案左側的複選標記,謝謝! – 2012-03-21 15:19:42
在遵循以下Microsoft文檔之後,我遇到了同樣的問題:https://msdn.microsoft.com/en-us/library/ms188910.aspx感謝您的修復和解釋。 – Nick 2015-02-26 09:39:18