ENCRYPTBYPASSPHRASE (Transact-SQL)ENCRYPTBYPASSPHRASE (Transact-SQL)

适用于: 是SQL Server是Azure SQL 数据库否Azure SQL 数据仓库否并行数据仓库APPLIES TO: yesSQL Server yesAzure SQL Database noAzure SQL Data Warehouse noParallel Data Warehouse

通过使用 TRIPLE DES 算法以及 128 密钥位长度的通行短语对数据加密。Encrypt data with a passphrase using the TRIPLE DES algorithm with a 128 key bit length.

主题链接图标 TRANSACT-SQL 语法约定Topic link icon Transact-SQL Syntax Conventions

语法Syntax

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

参数Arguments

passphrase passphrase
用于生成对称密钥的通行短语。A passphrase from which to generate a symmetric key.

@passphrase
类型为 nvarchar、char、varchar、binary、varbinary 或 nchar 的变量,其中包含用于生成对称密钥的通行短语 。A variable of type nvarchar, char, varchar, binary, varbinary, or nchar containing a passphrase from which to generate a symmetric key.

cleartext cleartext
要加密的明文。The cleartext to be encrypted.

@cleartext
类型为 nvarchar、char、varchar、binary、varbinary 或 nchar 的变量,其中包含明文 。A variable of type nvarchar, char, varchar, binary, varbinary, or nchar containing the cleartext. 最大大小为 8000 个字节。Maximum size is 8,000 bytes.

add_authenticator add_authenticator
指示是否将验证器与明文一起加密。Indicates whether an authenticator will be encrypted together with the cleartext. 如果将添加验证器,则为 1。1 if an authenticator will be added. int 。int.

@add_authenticator
指示是否将哈希与明文一起加密。Indicates whether a hash will be encrypted together with the cleartext.

authenticator authenticator
用于派生验证器的数据。Data from which to derive an authenticator. sysname 。sysname.

@authenticator
包含验证器所源自的数据的变量。A variable containing data from which to derive an authenticator.

返回类型Return Types

varbinary(最大大小为 8000 个字节) 。varbinary with maximum size of 8,000 bytes.

RemarksRemarks

通行短语是包含空格的密码。A passphrase is a password that includes spaces. 使用通行短语的优点在于,与相对较长的字符串相比,有含义的短语或句子更容易记忆。The advantage of using a passphrase is that it is easier to remember a meaningful phrase or sentence than to remember a comparably long string of characters.

此函数不检查密码复杂性。This function does not check password complexity.

示例Examples

以下示例将更新 SalesCreditCard 表中的记录,并使用主键作为验证器来加密存储在 CardNumber_EncryptedbyPassphrase 列中的信用卡号的值。The following example updates a record in the SalesCreditCard table and encrypts the value of the credit card number stored in column CardNumber_EncryptedbyPassphrase, using the primary key as an authenticator.

USE AdventureWorks2012;  
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  

另请参阅See Also

DECRYPTBYPASSPHRASE (Transact-SQL) DECRYPTBYPASSPHRASE (Transact-SQL)
加密层次结构Encryption Hierarchy