Backup certificate WITH PRIVATE KEY error create on other instance

Alen Cappelletti 1,037 Reputation points
2025-01-09T22:46:07.7033333+00:00

Hi,

I'm having trouble performing a backup of a certificate and subsequently restoring it on another server. I'll share the entire syntax. It's not clear to me whether I need to open the MASTER KEY on the source server.

I created a share at C:\TDE where I stored the certificates and the KEY, which has FULL permissions for the to SQL engine of each instance (I'm on DEV n my machine).

I'm performing these operations from SSMS and logged in as an administrator.

/* SERVER A (default instance) */
-- I need this below?
OPEN MASTER KEY DECRYPTION BY PASSWORD = 'NuovaPasswordMasterKey';
GO

BACKUP CERTIFICATE [TDE_DEV_2025_ShortLife_HP_PROBOOK]
TO FILE = 'C:\TDE\TDE_DEV_2025_ShortLife_HP_PROBOOK.cer'
WITH PRIVATE KEY (
    FILE = 'C:\TDE\TDE_DEV_2025_ShortLife_HP_PROBOOK.pvk',
    ENCRYPTION BY PASSWORD = 'PasswordPrivata'
)
GO

CLOSE MASTER KEY
GO

/* SERVER B (named instance same DEV host) */
CREATE CERTIFICATE [restored__TDE_DEV_2025_ShortLife_HP_PROBOOK]
FROM FILE = 'C:\TDE\TDE_DEV_2025_ShortLife_HP_PROBOOK.cer'
WITH PRIVATE KEY (
    FILE = 'C:\TDE\TDE_DEV_2025_ShortLife_HP_PROBOOK.pvk',
    DECRYPTION BY PASSWORD = 'PasswordPrivata'
)
GO

as you an see... the backup produce

User's image

but when try to restore I got always
Msg 15208, Level 16, State 6, Line 23

The certificate, asymmetric key, or private key file is not valid or does not exist; or you do not have permissions for it.

from SQL 2019 to SQL2022... but aren't backup...
I think it doesn't count for anything for certificate

Thanks ALEN

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
14,369 questions
0 comments No comments
{count} votes

Accepted answer
  1. Erland Sommarskog 115.9K Reputation points MVP
    2025-01-09T23:06:12.94+00:00

    What it says. You need to give the service account for the other instance permissions on the key files. Righ-click the file, select properties, and then go to the security tab.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.