SignByCert (Transact-SQL)

使用证书对文本进行签名并返回签名。

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

语法

SignByCert ( certificate_ID , @cleartext [ , 'password' ] )

参数

  • certificate_ID
    当前数据库中证书的 ID。certificate_ID 的数据类型为 int。

  • @cleartext
    类型为 nvarchar、char、varchar 或 nchar 的变量,其中包含要签名的数据。

  • 'password'
    用来对证书私钥进行加密的密码。password 的数据类型为 nvarchar(128)。

返回类型

最大大小为 8,000 个字节的 varbinary。

注释

需要对证书具有 CONTROL 权限。

示例

以下示例将用证书 ABerglundCert07 来签署 @SensitiveData 中的文本,该证书已用密码“pGFD4bb925DGvbd2439587y”进行解密。然后,它在 SignedData04 表中插入明文和签名。

DECLARE @SensitiveData nvarchar(max);
SET @SensitiveData = N'Saddle Price Points are 
    2, 3, 5, 7, 11, 13, 17, 19, 23, 29';
INSERT INTO [SignedData04]
    VALUES( N'data signed by certificate ''ABerglundCert07''',
    @SensitiveData, SignByCert( Cert_Id( 'ABerglundCert07' ), 
    @SensitiveData, N'pGFD4bb925DGvbd2439587y' ));
GO