Configuring MS SQL Server as the Backend Database
Key Manager Plus is bundled with PostgreSQL as its default backend database. It also supports Microsoft SQL Server and Azure SQL as alternative database options. This document provides detailed instructions on how to set up Microsoft SQL Server as the backend database for your Key Manager Plus installation, ensuring a seamless transition and optimal performance for your deployment.
Configuring SQL Server as the backend database using this procedure does not migrate any existing data from the bundled PostgreSQL database. If you have already been using Key Manager Plus with PostgreSQL, your existing data will not be carried over to SQL Server.
We recommend using a dedicated service account to run the Key Manager Plus service. Ensure that the service account is part of the local admin group in the server, where Key Manager Plus is running. The service account that is used for Key Manager Plus service and the change DB process should have the following permissions:
- In the SQL server, select the required account. Under Server roles, provide dbcreator privileges.
- Once the database is created, select the account and provide db_owner privileges.
To ensure a high level of security, Key Manager Plus has been configured to connect to SQL Server only through SSL. SSL should be enabled on SQL Server before configuring it as the backend database.
This document covers the following topics:
- Preparing the Server Certificate for Microsoft SQL Server
- Installing the Certificate in Microsoft SQL Server
- Importing the Certificate into Key Manager Plus
- Enabling SSL Encryption in Microsoft SQL Server
- Configuring Microsoft SQL Server as the Backend Database
1. Preparing the Server Certificate for Microsoft SQL Server
Before you begin with the configuration, generate or obtain a valid SSL certificate for the SQL Server. The certificate should include the SQL Server's fully qualified domain name (FQDN) or hostname used for the database connection.
Key Manager Plus supports both CA-signed and self-signed SSL certificates. Both options can be initiated from within the product:
- CA-signed certificate: Generate a Certificate Signing Request (CSR) from the Key Manager Plus interface and submit it to a trusted Certificate Authority (CA). The CA can be a recognized public CA or your organization's internal CA. Once issued, the CA will provide the signed SSL certificate, typically in .cer or .crt format.
- Self-signed certificate: Create a self-signed certificate directly from the Key Manager Plus interface, without requiring a CA. Refer to this help documentation for instructions. When creating a self-signed certificate, specify the SQL Server's FQDN in the Certificate Name field.
Certificate Requirements for SQL Server Clusters
For a clustered SQL Server environment, the certificate should cover all applicable SQL Server DNS or cluster names in the certificate. For example:
- Common Name (CN): SQL Server DNS alias
- Subject Alternative Names (SANs):
- SQL Server node hostnames and FQDNs
- SQL Server DNS alias hostname and FQDN
2. Installing the Certificate in Microsoft SQL Server
After obtaining the SSL certificate, import it along with its private key into the SQL Server's local certificate store using the Microsoft Management Console (MMC). Follow the steps below on the machine where SQL Server is running.
- Open Microsoft Management Console (MMC) with administrator rights on your machine.
- From the Console window that opens, select Add/Remove Snap-in.
- Click Add, select Certificates, and click Add again.
- When prompted, choose to manage certificates for the Computer Account, then click Finish.
- In the left pane, navigate to Certificates (Local Computer) >> Personal >> Certificates.
- Right-click Certificates, select All Tasks, and click Import.
- Browse to the location of your certificate file (in .pfx format, which includes the private key), select it, and complete the import process.

After importing the certificate, grant the SQL Server service account the required permission to access the certificate's private key:
- Navigate to Certificates (Local Computer) >> Personal >> Certificates.
- Right-click the imported certificate, select All Tasks, and click Manage Private Keys.
- In the permissions dialog, add the SQL Server service account and grant it Read access.
- Click OK to apply the changes.
3. Importing the Certificate into Key Manager Plus
The SQL server certificate should be imported into the Key Manager Plus certificate repository to establish a trusted SSL connection with SQL Server. The certificate to import depends on the type of SSL certificate in use:
- CA-signed certificate: Import the root CA certificate (and any intermediate CA certificates, if applicable) that issued the SQL Server certificate.
- Self-signed certificate: Import the SQL Server's self-signed certificate itself.
To import the certificate, follow these steps:
- Copy the certificate file (.cer or .crt) to the bin folder in the Key Manager Plus installation directory.
- Open Command Prompt as administrator and navigate to the bin folder in the installation directory.
- Execute the following command to add the certificate to the Key Manager Plus certificate store: importCert.bat <certificate_name>
Replace <certificate_name> with the file name of the certificate you copied.
This step is required for Key Manager Plus to trust the SSL connection with SQL Server. Ensure that you have successfully imported the SQL Server certificate into Key Manager Plus before proceeding to configure SQL Server as the backend.
4. Enabling SSL Encryption in Microsoft SQL Server
After installing the certificate, enable SSL encryption on the SQL Server using the SQL Server Configuration Manager. This step should be completed before configuring SQL Server as the Key Manager Plus backend database.
- On the SQL Server machine, open the SQL Server Configuration Manager.
- In the left pane, expand SQL Server Network Configuration.
- Right-click Protocols for the applicable SQL Server instance, and select Properties.
- Go to the Certificate tab and verify that the required SQL server certificate is selected.
- On the Flags tab, set Force Encryption as required:
- Set to Yes to require SSL for all connections to this SQL Server instance. This is the recommended configuration.
- Set to No if you prefer the client application to request encryption. This is not recommended, as it may result in unencrypted communications.


- Click OK to apply the changes.
- Restart the SQL Server service for the changes to take effect.
For more details, refer to this document about configuring SSL for SQL Server.
5. Configuring Microsoft SQL Server as the Backend Database
Follow these steps to configure SQL Server as the Backend Database:
- Log in to the Key Manager Plus server using the account that runs the Key Manager Plus service.
- Open Command Prompt as Administrator.
- Navigate to the <Key-Manager-Plus-Installation-Directory>\bin folder and execute the following command:
ChangeDB.bat - In the pop-up window that opens, click Open the best practices document to review the Best Practices Guide. Then click Continue with setup to proceed.

- In the DB Change Configuration window that opens, enter the following details:
- Server Type: Select SQL Server.

- Host Name:Enter the hostname, IP address, or FQDN of the SQL Server, followed by the port number. For example, sqlserver.example.com:1433. For a clustered SQL Server environment, specify the applicable SQL Server DNS or cluster alias name used for the connection.
Since Key Manager Plus connects to SQL Server only in SSL mode, it is recommended that you create a dedicated SQL Server instance running on a specific port for Key Manager Plus. To use a port other than 1433, specify it in the Host Name field as <hostname>:<port>.
- Instance Name: Specify the named instance of the SQL Server, if applicable. If left blank, Key Manager Plus will attempt to connect to the default instance on port 1433.
- Database Name: Enter the name of the Key Manager Plus database. The default name is pki. If you want to use a different name, specify it here. Key Manager Plus will automatically create the required master key, symmetric key, and other database objects.
- Authentication: The way by which you want to connect to the SQL server. Choose Windows, if you are connecting to the SQL server from Windows. Make use of the Windows Single Sign On facility, provided the Key Manager Plus service is running with a service account, which has the privilege to connect to the SQL server. Otherwise, select the option SQL.
It is recommended to choose the option Windows, as the Username and Password used for authentication are not stored anywhere.
- User Name and Password: If you have selected the option SQL in step v, specify the user name and password with which Key Manager Plus can connect to the database.
- The User Name and Password entered here will be stored in the database_params.conf file in Key Manager Plus. So, take care of hardening the host.
- You can use even your Windows login credentials, if you are connecting to the database from Windows. In this case, you need to enter the User Name as <domain-name>\<username>.
- Encryption Key: Select Default to allow Key Manager Plus to generate an encryption key automatically. Select Custom to use your own key. If you select Custom, you should manually create the following in SQL Server before proceeding:Once created, provide the Certificate Name and Symmetric Key Name in the configuration window.
- Finally, click Test to verify that Key Manager Plus can successfully connect to SQL Server using the details provided. Ensure the test completes successfully before proceeding.
- Click Save to apply the configuration.
After saving the configuration, navigate to the <Key-Manager-Plus-Installation-Directory>\conf folder and move the masterkey.key file to a secure location outside the installation directory. SQL Server encrypts data using a hierarchical encryption infrastructure. The masterkey.key file contains the password used to protect the Database Master Key, which is critical to this encryption chain. If this file is lost, you will need to reconfigure the SQL Server setup from the beginning. This file is also required when setting up High Availability or Disaster Recovery for Key Manager Plus. Keep this file in a safe and accessible location. For more details on encryption and key management in SQL Server, refer to this MSDN document.
Restart the Key Manager Plus service. Verify that Key Manager Plus starts successfully and connects to SQL Server. You have now successfully configured SQL Server as the backend database for Key Manager Plus.