ALTER SYMMETRIC KEY (Transact-SQL)
Changes the properties of a symmetric key.
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
Caution |
|---|
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.
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.
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 = '<enterStrongPasswordHere>';
-- First, encrypt the key with a password.
ALTER SYMMETRIC KEY JanainaKey043
ADD ENCRYPTION BY PASSWORD = '<enterStrongPasswordHere>';
-- Now remove encryption by the certificate.
ALTER SYMMETRIC KEY JanainaKey043
DROP ENCRYPTION BY CERTIFICATE Shipping04;
CLOSE SYMMETRIC KEY JanainaKey043;