1 CREATE SYMMETRIC KEY key1 WITH ALGORITHM=DES 2 ENCRYPTION BY PASSWORD='abc$123' 3 GO 4 5 OPEN SYMMETRIC KEY key1 6 DECRYPTION BY PASSWORD='abc$123' 7 8 DECLARE @str NVARCHAR(100),@Encrypted VARBINARY(MAX) 9 SET @str=N'要加密的字串' 10 SELECT @Encrypted=ENCRYPTBYKEY(KEY_GUID('key1'),@str) 11 SELEcT '加密'=@Encrypted ,'解密'=CAST(DECRYPTBYKEY(@Encrypted) AS NVARCHAR(100)) 12 CLOSE SYMMETRIC KEY key1 13 GO 14 DROP SYMMETRIC KEY key1 15 GO
--SQL2005中自带DES加密算法