ALTER SYMMETRIC KEY (Transact-SQL)

Changes the properties of a symmetric key.

Topic link iconTransact-SQL Syntax Conventions

Syntax

ALTER SYMMETRIC KEY Key_name <alter_option>

<alter_option> ::=
   ADD ENCRYPTION BY <encrypting_mechanism> [ , ... n ]
   | 
   DROP ENCRYPTION BY <encrypting_mechanism> [ , ... n ]

<encrypting_mechanism> ::=
   CERTIFICATE certificate_name
   |
   PASSWORD = 'password'
   |
   SYMMETRIC KEY Symmetric_Key_Name
   |
   ASYMMETRIC KEY Asym_Key_Name

Arguments

  • Key_name
    Is the name by which the symmetric key to be changed is known in the database.
  • ADD ENCRYPTION BY
    Adds encryption by using the specified method.
  • DROP ENCRYPTION BY
    Drops encryption by the specified method. You cannot remove all the encryptions from a symmetric key.
  • CERTIFICATE Certificate_name
    Specifies the certificate that is used to encrypt the symmetric key. This certificate must already exist in the database.
  • PASSWORD ='password'
    Specifies the password that is used to encrypt the symmetric key.
  • SYMMETRIC KEY Symmetric_Key_Name
    Specifies the symmetric key that is used to encrypt the symmetric key that is being changed. This symmetric key must already exist in the database and must be open.
  • ASYMMETRIC KEY Asym_Key_Name
    Specifies the asymmetric key that is used to encrypt the symmetric key that is being changed. This asymmetric key must already exist in the database.

Remarks

Warning

When a symmetric key is encrypted with a password instead of with the public key of the database master key, the TRIPLE_DES encryption algorithm is used. Because of this, keys that are created with a strong encryption algorithm, such as AES, are themselves secured by a weaker algorithm.

To change the encryption of the symmetric key, use the ADD ENCRYPTION and DROP ENCRYPTION phrases. It is never possible for a key to be entirely without encryption. For this reason, the best practice is to add the new form of encryption before removing the old form of encryption.

To change the owner of a symmetric key, use ALTER AUTHORIZATION.

Permissions

Requires ALTER permission on the symmetric key. If adding encryption by a certificate or asymmetric key, requires VIEW DEFINITION permission on the certificate or asymmetric key. If dropping encryption by a certificate or asymmetric key, requires CONTROL permission on the certificate or asymmetric key.

Examples

The following example changes the encryption method that is used to protect a symmetric key. The symmetric key JanainaKey043 is encrypted using certificate Shipping04 when the key was created. Because the key can never be stored unencrypted, in this example, encryption is added by password, and then encryption is removed by certificate.

CREATE SYMMETRIC KEY JanainaKey043 WITH ALGORITHM = AES_256 
    ENCRYPTION BY CERTIFICATE Shipping04;
-- Open the key. 
OPEN SYMMETRIC KEY JanainaKey043 DECRYPTION BY CERTIFICATE Shipping04
    WITH PASSWORD = 'pGFD4bb925DGvbd2439587y'; 
-- First, encrypt the key with a password.
ALTER SYMMETRIC KEY JanainaKey043 
    ADD ENCRYPTION BY PASSWORD = '4350$98fdlxk4Bj9oFD9h4';
-- Now remove encryption by the certificate.
ALTER SYMMETRIC KEY JanainaKey043 
    DROP ENCRYPTION BY CERTIFICATE Shipping04;
CLOSE SYMMETRIC KEY JanainaKey043;

See Also

Reference

CREATE SYMMETRIC KEY (Transact-SQL)
OPEN SYMMETRIC KEY (Transact-SQL)
CLOSE SYMMETRIC KEY (Transact-SQL)
DROP SYMMETRIC KEY (Transact-SQL)

Other Resources

Encryption Hierarchy

Help and Information

Getting SQL Server 2005 Assistance