Skip to content

Using Self Signed Certificate with SqlClient

Lawrence Cheung edited this page Dec 13, 2022 · 4 revisions

Self-Signed Certificate

Before we start let's have a brief look at Self-Signed Certificate definition:

In cryptography and computer security, self-signed certificates are public key certificates that are not issued by a certificate authority (CA). These self-signed certificates are easy to make and do not cost money. However, they do not provide any trust value. Read more

Creating a self-Certificate

Remember that the subject of a self-signed certificate must be the very same name as the FQDN.

  1. Change <FQDN> in -Subject property to your Fully Qualified Domain Name (FQDN) int the following PowerShell command and run it:
New-SelfSignedCertificate -Subject "CN=<FQDN>" -KeyAlgorithm RSA -KeyLength 2048 -CertStoreLocation "cert:\LocalMachine\My" -TextExtension @("2.5.29.17={text}DNS=localhost&IPAddress=127.0.0.1&IPAddress=::1") -HashAlgorithm "SHA256" -Type SSLServerAuthentication -Provider "Microsoft RSA SChannel Cryptographic Provider"
  1. type in search area the keyword run. When the Run application is opened type in mmc.
  2. Click on Add/Remove Snap-in
  3. In the left column click on Certificates and then click on Add > button.
  4. Select Computer account and click Next > and click Finish. You should be seeing something similar to the below picture:

image

  1. Press OK.

image

  1. Now in the left panel, under Personal select Certificate.
  2. On the right panel you should be able to see the newly created certificate. The name will be your FQDN.
  3. Right click on the certificate > All Tasks > Manage Private Key

tempsnip

  1. Add required permission for SQL server instance user (NT Service\MSSQLSERVER).

Now you should be able to import this certificate to SQL server using SQL Server Configuration Manager.

Clone this wiki locally