top of page

What is Public Key and Private Key?

Oct 27
8 min read
What is Public Key and Private Key?

 

A public key and a private key are mathematically related parts of an asymmetric cryptographic key pair. The public key can be shared, while the private key must be protected. Depending on the algorithm and protocol, the pair can support encryption, digital signatures or key agreement.

 

The roles depend on the operation. In a suitable public key encryption scheme, someone can encrypt data using the recipient's public key and the recipient can decrypt it using the private key. In a digital signature scheme, the private key signs and the corresponding public key verifies the signature. Not every key type supports both operations.

 

How do public and private keys work?

 

An algorithm generates related key material so that the public key can be distributed without making it practical, under the scheme's security assumptions, to derive the private key from it. The keys are not interchangeable passwords and the relationship is not a promise of absolute security. Randomness, implementation, key protection and the strength of the chosen algorithm all matter.

 

The illustration shows the distinct roles: two related keys, a public key that can be shared, a protected private key, encryption in a suitable scheme and signature verification. It is a conceptual guide; actual protocols add important steps and checks.

 

Public and private key infographic showing key pairs, encryption and signature verification

 

The NIST public key glossary describes public keys in the context of asymmetric algorithms, including signature verification and encryption. A key must also be suitable for the specific algorithm and purpose.

 

Public key vs private key

 

Feature

Public key

Private key

Visibility

Can be distributed

Must remain controlled and protected

Encryption scheme

Can encrypt to its owner where the scheme supports encryption

Can decrypt the corresponding ciphertext in that scheme

Signature scheme

Verifies a signature

Produces a signature

Identity

Needs a trustworthy binding to its claimed owner

Control helps demonstrate possession, subject to the protocol

Exposure

Normally intended to be shared, but must be authentic

Exposure can allow misuse and requires a response

 

A certificate, key fingerprint and public key are related but are not the same thing. A certificate contains a public key and identity information signed by an issuer. A fingerprint is a compact representation used to compare key material. Neither makes a private key public.

 

How does public key encryption work?

 

Imagine a sender wants to protect a message for a recipient. In a public key encryption scheme, the sender obtains the recipient's authentic public key and uses the appropriate algorithm to encrypt. The recipient uses the corresponding private key to decrypt. If an attacker substitutes their own public key before encryption, the sender may unknowingly encrypt for the attacker instead. Verifying the key's owner is therefore essential.

 

Real systems often use hybrid encryption: public key techniques establish or protect a symmetric key, and a symmetric cipher protects the bulk data. The exact design depends on the protocol. Public key encryption by itself does not prove who sent a message or guarantee that the recipient's key was obtained from the right person.

 

Do not treat a digital signature as simply encrypting a message with a private key. Modern signature algorithms have their own defined signing and verification operations and do not provide message confidentiality.

 

How do digital signatures work?

 

The signer uses a private signing key to generate a signature over the message or an algorithm-defined representation of it. A verifier uses the corresponding public key to check whether the signature is valid for the message. A valid signature provides evidence that the signing key was used and that the signed data has not been altered in a way that passes verification.

 

A signature does not make the message secret. It also does not automatically establish the real-world identity of the signer: the verifier must trust the association between the public key and that identity. If the private key is stolen, an attacker may create valid signatures until the compromise is detected and addressed.

 

What is key agreement?

 

Key agreement lets parties derive a shared secret from their own private material and exchanged public information. The derived secret can then be used to create symmetric keys for a connection. This is a different operation from directly encrypting an entire message with a recipient's public key.

 

For example, ephemeral Diffie-Hellman based key agreement in a suitable protocol can provide forward secrecy: a later compromise of a long-term authentication key does not by itself reveal previously recorded session keys, provided ephemeral secrets are protected and erased appropriately. This does not protect traffic already exposed through a compromised endpoint or leaked session key.

 

How are keys used in HTTPS?

 

When a browser connects to a website over HTTPS, TLS establishes a protected connection and normally authenticates the server. In a certificate-based TLS 1.3 handshake, the server presents a certificate and proves control of its private signing key; the browser checks the certificate chain and hostname under its trust rules. The parties use key agreement to derive symmetric traffic keys.

 

RFC 9846 specifies TLS 1.3, replacing RFC 8446. The protocol also supports pre-shared key modes, so certificate use and forward secrecy depend on the chosen mode and configuration. It would be misleading to say that every HTTPS connection encrypts all website data directly with the certificate's public key.

 

HTTPS protects the browser-to-service connection, subject to its endpoints and configuration. It does not prove that a website's business is trustworthy, prevent a user entering information into an impostor site, or automatically secure data after the endpoint receives it.

 

How are keys used in SSH?

 

With SSH key authentication, a client signs session-specific authentication data using its private key. The server checks the signature and whether the matching public key is authorised for the requested account. The private key is not sent during that authentication.

 

SSH also has server host keys: the client must check that it is connecting to the intended server. User keys and host keys have different jobs. If a host key changes unexpectedly, verify its fingerprint through a trusted independent channel before proceeding. The mechanism is specified in RFC 4252.

 

How do passkeys use public and private keys?

 

A passkey uses a cryptographic authenticator linked to a service. The service registers a public key, and the authenticator uses the matching private key to sign a challenge. The user may unlock the authenticator with a device PIN or biometric check. Depending on the implementation, passkeys may be synchronised through a protected account or held on a single device or security key.

 

Passkeys are designed to resist phishing, but they do not remove the need to secure devices, synchronisation accounts and recovery methods. Our credential guide explains how a passkey relates to other sign-in credentials.

 

Public key cryptography vs symmetric encryption

 

Question

Public key cryptography

Symmetric cryptography

Key arrangement

Related public and private key material

The same shared secret key is used for related operations

Common uses

Signatures, key agreement and supported public key encryption

Protecting bulk data and traffic with a shared session key

Distribution challenge

Verify that the public key belongs to the intended party

Protect the shared key when establishing and storing it

Typical role in a secure connection

Authentication or establishing key material

Encrypting and authenticating ongoing traffic

 

This is a functional comparison, not a speed benchmark. Real protocols combine methods, and performance depends on algorithms, hardware, implementation and workload. A public key does not replace every symmetric session key in a secure connection.

 

How do you know a public key is genuine?

 

A public key can be freely distributed, but an attacker could substitute a different one. A trusted binding connects the key to the intended identity or service. Different systems use different trust models.

 

  • Web browsers normally validate a server certificate chain, hostname and other applicable checks against trusted certificate authorities.

  • SSH clients may compare a server host key fingerprint with a known value, or validate an SSH host certificate under a trusted authority.

  • A user may verify a key fingerprint through a separate trusted channel before using it to protect sensitive data.

  • An organisation may distribute trusted keys or certificates through managed systems and policies.

 

A certificate is not automatically trustworthy because it exists. Its chain, scope, identity, validity and other checks matter. Similarly, a fingerprint obtained from the same unverified connection may not protect against an attacker who controls that connection.

 

How should private keys be protected?

 

Private key protection should reflect what the key can authorise and where it is used. A key used for a public website, an administrator's SSH access and a personal passkey have different operational needs.

 

  • Generate keys using a reputable, supported implementation and a suitable source of randomness.

  • Restrict access to private keys and use secure hardware or protected storage where appropriate.

  • Protect key files with a strong passphrase when practical, and secure the device and any unlocked agent.

  • Limit the permissions associated with each key and avoid sharing one private key unnecessarily.

  • Keep an inventory of where keys are trusted, their owner and how they can be replaced or revoked.

  • Back up keys only where appropriate, with equivalent protection and a tested recovery process. Some hardware keys are intentionally non-exportable.

  • Monitor for compromise, update algorithms and software, and plan key rotation without losing access to dependent systems.

 

The NIST key management guidance addresses protection and management throughout a key's lifecycle. Key rotation alone is not a substitute for understanding who can use a key and where it is trusted.

 

What happens if a private key is compromised?

 

Treat the key as potentially usable by an attacker. Identify the systems and accounts that trust the corresponding public key, revoke or remove that trust using the appropriate process, and create replacement key material on a trusted system. Investigate affected access and review logs, certificates, dependent applications and recovery paths.

 

The impact depends on the key's purpose. An exposed signing key may enable forged signatures. An exposed decryption key may put accessible ciphertext at risk. In SSH, removing an authorised public key usually prevents new logins using that key, but existing sessions may need separate termination. Changing a file's passphrase alone does not replace the compromised key pair.

 

Certificate revocation and trust updates have practical limitations and timing differences across systems. Follow the relevant service's incident process and do not assume every client learns of a change immediately.

 

What does this mean for broadband users?

 

A broadband connection carries traffic between devices and services. Public key cryptography helps protocols establish trust or protect communication across that path; it does not increase the line's speed or automatically protect an unsecured device. A UK user logging into a remote server may depend on DNS, network reachability, SSH host verification and user authentication in sequence. A failure in one does not prove the others are broken.

 

For example, if a server is unreachable, investigate the address, port and network path. If it is reachable but shows an unexpected host key, verify identity. If host verification succeeds but login fails, check the authorised user key and account policy. Our authentication guide explains the identity check, while access control covers permissions after it.

 

Frequently asked questions

 

Can I share my public key?

 

Yes, public keys are intended to be shared. Make sure recipients can verify that the key really belongs to you, and understand where registering it may grant access.

 

Should I share my private key?

 

Keep it protected and share it only where a carefully designed system explicitly requires controlled access. For normal SSH user authentication, you do not send the private key to the server.

 

Can a public key decrypt a message?

 

That depends on the algorithm and operation. In a suitable public key encryption scheme, the recipient's private key decrypts data encrypted to its public key. Signature verification is a different operation.

 

Does a digital signature encrypt a message?

 

No. A signature helps verify signed data and the use of the signing key. It does not by itself keep the message confidential.

 

Is a certificate the same as a public key?

 

No. A certificate contains a public key and associated information, signed by an issuer. Its usefulness depends on validation and trust.

 

What if I lose my private key?

 

You may lose access to systems or encrypted data that depend on it. Use the system's documented recovery process and remove obsolete authorised keys where appropriate.

 

Does HTTPS use the same keys for every connection?

 

Not necessarily. A server may use a longer-lived certificate key for authentication, while connection-specific traffic keys are derived during the handshake. Details depend on the TLS version and mode.

 

Key takeaway

 

Public and private keys form a related pair with different jobs. Share authentic public keys, protect private keys and understand whether the system is using them for encryption, signatures or key agreement. Secure outcomes also depend on identity checks, implementation and key management.

 
 
UK Techie Broadband Providers
bottom of page