Click to Rate and Give Feedback
MSDN
MSDN Library
SQL Server
SQL Server 2008
Database Engine
Technical Reference
 ENCRYPTBYASYMKEY (Transact-SQL)
Community Content
In this section
Statistics Annotations (0)
Collapse All/Expand All Collapse All
Other versions are also available for the following:
SQL Server 2008 Books Online (October 2009)
ENCRYPTBYASYMKEY (Transact-SQL)

Encrypts data with an asymmetric key.

Topic link icon Transact-SQL Syntax Conventions

EncryptByAsymKey ( Asym_Key_ID , { 'plaintext' | @plaintext } )
Asym_Key_ID

Is the ID of an asymmetric key in the database. int.

cleartext

Is a string of data that will be encrypted with the asymmetric key.

@plaintext

Is a variable of type nvarchar, char, varchar, binary, varbinary, or nchar that contains data to be encrypted with the asymmetric key.

varbinary with a maximum size of 8,000 bytes.

Encryption and decryption with an asymmetric key is very costly compared with encryption and decryption with a symmetric key. We recommend that you not encrypt large datasets, such as user data in tables, using an asymmetric key. Instead, you should encrypt the data using a strong symmetric key and encrypt the symmetric key using an asymmetric key.

The following example encrypts the text stored in @cleartext with the asymmetric key JanainaAsymKey02. The encrypted data is inserted into the ProtectedData04 table.

INSERT INTO [AdventureWorks].[Sales].[ProtectedData04] 
    values( N'data encrypted by asymmetric key ''JanainaAsymKey02''',
    EncryptByAsymKey(AsymKey_ID('JanainaAsymKey02'), @cleartext) )
GO
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker