Advertisement
Beginner ASP.NET Core, HTTPS, Certificates & Transport Security

What is the difference between a certificate's public key and private key, and why must the private key never be exposed or committed to source control?

Short answer

The public key (embedded in the certificate itself, freely shared with anyone) is used by clients to encrypt data or verify signatures, while the private key (kept secret, never shared) is used by the server to decrypt that data or create signatures -- if a private key is ever…

Save ASP.NET Core mock interview
Advertisement
AModel answer
The public key (embedded in the certificate itself, freely shared with anyone) is used by clients to encrypt data or verify signatures, while the private key (kept secret, never shared) is used by the server to decrypt that data or create signatures -- if a private key is ever exposed (accidentally committed to a public git repository, leaked in a log, etc.), an attacker could impersonate the server or decrypt intercepted traffic, requiring the certificate to be immediately revoked and reissued with a new key pair, making private key secrecy the single most critical operational security requirement of the entire TLS system.
Example

# .gitignore should always exclude private key material *.pfx *.key *.pem appsettings.Production.json # if it contains cert passwords # Store private keys in a secret manager instead # e.g., Azure Key Vault, AWS Secrets Manager, HashiCorp Vault

Real-world example
A security incident occurs after a developer accidentally commits a .pfx certificate file (including its private key) to a public GitHub repository, requiring the organization to immediately revoke that certificate, obtain a newly issued one with a fresh key pair, and treat the exposure window as a potential compromise.
Likely follow-ups
  • What immediate steps should be taken if a private key is discovered to have been exposed?
  • How do secret managers like Azure Key Vault reduce the risk of private key exposure compared to file-based storage?
Related topics