The Wayback Machine - http://web.archive.org/web/20140105205723/http://msdn.microsoft.com:80/zh-tw/library/ms181860(v=sql.90).aspx
匯出 (0) 列印
全部展開
Expand Minimize
本主題尚未接受評分 - 為這個主題評分

DecryptByKey (Transact-SQL)

使用對稱金鑰為資料解密。

主題連結圖示 Transact-SQL 語法慣例


DecryptByKey ( { 'ciphertext' | @ciphertext } 
              [ , add_authenticator 
                                , { authenticator | @authenticator } 
              ]
                          )
ciphertext

這是已經利用金鑰加密的資料。 varbinary。

@ciphertext

這是 varbinary 類型的變數,其中包含已利用金鑰加密的資料。

add_authenticator

指出驗證器是否要與純文字一起加密。必須是加密資料時傳遞至 EncryptByKey 的相同值。int。

authenticator

這是要產生驗證器的資料。必須符合已提供給 EncryptByKey 的值。sysname。

@authenticator

這是含有要產生驗證器之資料的變數。必須符合已提供給 EncryptByKey 的值。

varbinary,大小上限為 8,000 位元組。

DecryptByKey 使用對稱金鑰。這個對稱金鑰必須已在資料庫中開啟。同時可以開啟多個金鑰。為加密文字解密之前,您不需立即開啟金鑰。

對稱加密和解密相當快速,而且很適合處理大量資料。

A. 使用對稱金鑰解密

下列範例是利用對稱金鑰為加密文字解密。

-- First, open the symmetric key with which to decrypt the data.
OPEN SYMMETRIC KEY SSN_Key_01
   DECRYPTION BY CERTIFICATE HumanResources037;
GO

-- Now list the original ID, the encrypted ID, and the 
-- decrypted ciphertext. If the decryption worked, the original
-- and the decrypted ID will match.
SELECT NationalIDNumber, EncryptedNationalID 
    AS 'Encrypted ID Number',
    CONVERT(nvarchar, DecryptByKey(EncryptedNationalID)) 
    AS 'Decrypted ID Number'
    FROM HumanResources.Employee;
GO

B. 使用對稱金鑰和驗證雜湊解密

下列範例會為隨驗證器一同加密的資料解密。

-- First, open the symmetric key with which to decrypt the data
OPEN SYMMETRIC KEY CreditCards_Key11
   DECRYPTION BY CERTIFICATE Sales09;
GO

-- Now list the original card number, the encrypted card number,
-- and the decrypted ciphertext. If the decryption worked, 
-- the original number will match the decrypted number.
SELECT CardNumber, CardNumber_Encrypted 
    AS 'Encrypted card number', CONVERT(nvarchar,
    DecryptByKey(CardNumber_Encrypted, 1 , 
    HashBytes('SHA1', CONVERT(varbinary, CreditCardID)))) 
    AS 'Decrypted card number' FROM Sales.CreditCard;
GO

本文對您有任何幫助嗎?
(剩餘 1500 個字元)

社群新增項目

新增
顯示:
© 2014 Microsoft. 著作權所有,並保留一切權利。