本文件已封存並已停止維護。
EncryptByPassPhrase (Transact-SQL)
SQL Server 2005
以密碼片語為資料加密。
- passphrase
-
要產生對稱金鑰的密碼片語。
- @passphrase
-
nvarchar、char、varchar、binary、varbinary, 或 nchar 類型的變數,其中包含要從中產生對稱金鑰的密碼片語。
- cleartext
-
要加密的純文字。
- @cleartext
-
nvarchar、char、varchar、binary、varbinary 或 nchar 類型的變數,其中包含純文字。大小上限是 8,000 位元組。
- add_authenticator
-
指出驗證器是否要與純文字一起加密。若要加入驗證器,則為 1。 int.
- @add_authenticator
-
指出雜湊是否要與純文字一起加密。
- authenticator
-
要衍生驗證器的資料。 sysname.
- @authenticator
-
含有要衍生驗證器之資料的變數。
下列範例會更新 SalesCreditCard 資料表中的記錄,並使用主索引鍵當做驗證器,加密儲存在資料行 CardNumber_EncryptedbyPassphrase 中的信用卡號碼之值。
USE AdventureWorks;
GO
-- Create a column in which to store the encrypted data.
ALTER TABLE Sales.CreditCard
ADD CardNumber_EncryptedbyPassphrase varbinary(256);
GO
-- First get the passphrase from the user.
DECLARE @PassphraseEnteredByUser nvarchar(128);
SET @PassphraseEnteredByUser
= 'A little learning is a dangerous thing!';
-- Update the record for the user's credit card.
-- In this case, the record is number 3681.
UPDATE Sales.CreditCard
SET CardNumber_EncryptedbyPassphrase = EncryptByPassPhrase(@PassphraseEnteredByUser
, CardNumber, 1, CONVERT( varbinary, CreditCardID))
WHERE CreditCardID = '3681';
GO
顯示:

