Click to Rate and Give Feedback
MSDN
MSDN Library
SQL Server
SQL Server 2008
Database Engine
Technical Reference
 SignByAsymKey (Transact-SQL)

  Switch on low bandwidth view
Community Content
In this section
Statistics Annotations (0)
Other versions are also available for the following:
SQL Server 2008 Books Online (June 2009)
SignByAsymKey (Transact-SQL)

Signs plaintext with an asymmetric key

Topic link icon Transact-SQL Syntax Conventions

SignByAsymKey( Asym_Key_ID , @plaintext [ , 'password' ] )
Asym_Key_ID

Is the ID of an asymmetric key in the current database. Asym_Key_ID is int.

@plaintext

Is a variable of type nvarchar, char, varchar, or nchar containing data that will be signed with the asymmetric key.

password

Is the password with which the private key is protected. password is nvarchar(128).

varbinary with a maximum size of 8,000 bytes.

Requires CONTROL permission on the asymmetric key.

The following example creates a table, SignedData04, in which to store plaintext and its signature. It next inserts a record in the table, signed with asymmetric key PrimeKey, which is first decrypted with password 'pGFD4bb925DGvbd2439587y'.

-- Create a table in which to store the data
CREATE TABLE [SignedData04]( Description nvarchar(max), Data nvarchar(max), DataSignature varbinary(8000) );
GO
-- Store data together with its signature
DECLARE @clear_text_data nvarchar(max);
set @clear_text_data = N'Important numbers 2, 3, 5, 7, 11, 13, 17, 
      19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79,
      83, 89, 97';
INSERT INTO [SignedData04] 
    VALUES( N'data encrypted by asymmetric key ''PrimeKey''',
    @clear_text_data, SignByAsymKey( AsymKey_Id( 'PrimeKey' ),
    @clear_text_data, N'pGFD4bb925DGvbd2439587y' ));
GO
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
The example is misleading      Mike C_1   |   Edit   |   Show History

This function will only sign the first 8,000 bytes of data in the plaintext. The function chops off everything after the 8,000th byte of data, ignoring it. The example indicates that the function will accept and sign an nvarchar(max) data type value, but again anything after the 8,000th byte is discarded. Below is a more accurate example:

-- Create a table in which to store the data
CREATE TABLE [SignedData04]( Description nvarchar(4000), Data nvarchar(4000), DataSignature varbinary(8000) );
GO
-- Store data together with its signature
DECLARE @clear_text_data nvarchar(4000);
set @clear_text_data = N'Important numbers 2, 3, 5, 7, 11, 13, 17, 
      19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79,
      83, 89, 97';
INSERT INTO [SignedData04] 
    VALUES( N'data encrypted by asymmetric key ''PrimeKey''',
    @clear_text_data, SignByAsymKey( AsymKey_Id( 'PrimeKey' ),
    @clear_text_data, N'pGFD4bb925DGvbd2439587y' ));
GO
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker