BACKUP CERTIFICATE (Transact-SQL)
Exports a certificate to a file.
Applies to: SQL Server (SQL Server 2008 through current version).
BACKUP CERTIFICATE certname TO FILE = 'path_to_file' [ WITH PRIVATE KEY ( FILE = 'path_to_private_key_file' , ENCRYPTION BY PASSWORD = 'encryption_password' [ , DECRYPTION BY PASSWORD = 'decryption_password' ] ) ]
If the private key is encrypted with a password in the database, the decryption password must be specified.
When you back up the private key to a file, encryption is required. The password used to protect the backed up certificate is not the same password that is used to encrypt the private key of the certificate.
To restore a backed up certificate, use the CREATE CERTIFICATEstatement.
A. Exporting a certificate to a file
The following example exports a certificate to a file.
BACKUP CERTIFICATE sales05 TO FILE = 'c:\storedcerts\sales05cert'; GO
B. Exporting a certificate and a private key
In the following example, the private key of the certificate that is backed up will be encrypted with the password 997jkhUbhk$w4ez0876hKHJH5gh.
BACKUP CERTIFICATE sales05 TO FILE = 'c:\storedcerts\sales05cert' WITH PRIVATE KEY ( FILE = 'c:\storedkeys\sales05key' , ENCRYPTION BY PASSWORD = '997jkhUbhk$w4ez0876hKHJH5gh' ); GO
C. Exporting a certificate that has an encrypted private key
In the following example, the private key of the certificate is encrypted in the database. The private key must be decrypted with the password 9875t6#6rfid7vble7r. When the certificate is stored to the backup file, the private key will be encrypted with the password 9n34khUbhk$w4ecJH5gh.
BACKUP CERTIFICATE sales09 TO FILE = 'c:\storedcerts\sales09cert' WITH PRIVATE KEY ( DECRYPTION BY PASSWORD = '9875t6#6rfid7vble7r' , FILE = 'c:\storedkeys\sales09key' , ENCRYPTION BY PASSWORD = '9n34khUbhk$w4ecJH5gh' ); GO