我需要使用DES编码一些字符串(不是三重DES - 我知道有很多文章描述了如何使用NCRYPTBYPASSPHRASE命令)。我有钥匙和IV。 我怎么用T-SQL做到这一点?有没有现成的程序或功能?
答案 0 :(得分:0)
从here翻录。我没有对此进行测试,但this页面列出了所有加密类型,DES似乎是其中之一。
--If there is no master key, create one now.
IF NOT EXISTS
(SELECT * FROM sys.symmetric_keys WHERE symmetric_key_id = 101)
CREATE MASTER KEY ENCRYPTION BY
PASSWORD = '23987hxJKL969#ghf0%94467GRkjg5k3fd117r$$#1946kcj$n44nhdlj'
GO
CREATE CERTIFICATE HumanResources037
WITH SUBJECT = 'Employee Social Security Numbers';
GO
CREATE SYMMETRIC KEY SSN_Key_01
WITH ALGORITHM = DES
ENCRYPTION BY CERTIFICATE HumanResources037;
GO
-- Open the symmetric key with which to encrypt the data.
OPEN SYMMETRIC KEY SSN_Key_01
DECRYPTION BY CERTIFICATE HumanResources037;
-- Encrypt the value
SET @encrypted = EncryptByKey(Key_GUID('SSN_Key_01'), '555-77-4444');