EncryptByPassPhrase (Transact-SQL)

用通行短语加密数据。

主题链接图标Transact-SQL 语法约定

语法

EncryptByPassPhrase ( { 'passphrase' | @passphrase } , 
                     { 'cleartext' | @cleartext }
                     [ , { add_authenticator | @add_authenticator }
                       , { authenticator | @authenticator } ]
                                        )

参数

  • passphrase
    用于生成对称密钥的通行短语。
  • @passphrase
    类型为 nvarcharcharvarcharbinaryvarbinary,nchar 的变量,其中包含用于生成对称密钥的通行短语。
  • cleartext
    要加密的明文。
  • @cleartext
    类型为 nvarcharcharvarcharbinaryvarbinarynchar 的变量,其中包含明文。最大大小为 8000 个字节。
  • add_authenticator
    指示是否将验证器与明文一起加密。如果将添加验证器,则为 1。 int.
  • @add_authenticator
    指示是否将哈希与明文一起加密。
  • authenticator
    用于派生验证器的数据。 sysname.
  • @authenticator
    包含验证器所源自的数据的变量。

返回类型

varbinary(最大大小为 8000 个字节)。

备注

通行短语是包含空格的密码。使用通行短语的优点在于,与相对较长的字符串相比,有含义的短语或句子更容易记忆。

此函数不检查密码复杂性。

示例

以下示例将更新 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

请参阅

参考

DecryptByPassPhrase (Transact-SQL)

其他资源

加密层次结构

帮助和信息

获取 SQL Server 2005 帮助