# What Is HSM (Hardware Security Module)? Definition and Examples

> HSM is a tamper-resistant hardware device that generates, stores and uses cryptographic keys internally so that private keys never leave it in plaintext.

Source: https://ssl.sh/glossary/hsm/
Last updated: 2026-11-10

A Hardware Security Module is a dedicated device (an appliance, PCIe card, USB token or cloud service) that performs cryptographic operations such as signing and decryption inside a protected boundary. Keys are generated inside the module and are normally marked non-extractable; applications send data in and receive results through interfaces such as PKCS #11. HSMs are usually validated under FIPS 140-2 or FIPS 140-3 through the [NIST Cryptographic Module Validation Program](https://csrc.nist.gov/projects/cryptographic-module-validation-program) or evaluated under Common Criteria.

## Why it matters
HSMs anchor the most valuable keys in PKI. CA/Browser Forum requirements oblige CAs to generate and protect their CA [private keys](https://ssl.sh/glossary/private-key/) in certified hardware, and code signing rules now require subscribers' signing keys to live in hardware as well, which is why [code signing certificates](https://ssl.sh/glossary/code-signing-certificate/) ship on tokens or through cloud signing services. Large TLS deployments, payment systems and banks also keep server keys in HSMs, sometimes combined with [SSL offloading](https://ssl.sh/glossary/ssl-offloading/) appliances.

## Example
```bash
# create a non-extractable P-256 key on a PKCS #11 token (SoftHSM shown for testing)
pkcs11-tool --module /usr/lib/softhsm/libsofthsm2.so --login \
  --keypairgen --key-type EC:prime256v1 --label tls-key
pkcs11-tool --module /usr/lib/softhsm/libsofthsm2.so --list-objects
```

## Common misconceptions
- **An HSM makes a compromised server harmless.** It prevents key theft, but an attacker controlling the server can still ask the HSM to sign while they have access.
- **Only CAs need HSMs.** Code signing keys must be hardware-protected too, and many regulated industries require HSMs for TLS or signing keys.
- **A TPM is the same as an HSM.** A TPM is a small chip tied to one machine; HSMs are built for high-volume, multi-application key management.

## Related terms

- [私钥](https://ssl.sh/zh/glossary/private-key/): 私钥是非对称密钥对中保密的那一半，TLS 服务器用它证明自己拥有证书里的那把公钥。
- [密钥轮换](https://ssl.sh/zh/glossary/key-rotation/): 密钥轮换是按计划或在安全事件后，用新生成的密钥替换旧密钥，以限制密钥泄露造成损失的做法。
- [代码签名证书](https://ssl.sh/zh/glossary/code-signing-certificate/): 代码签名证书是带有 codeSigning 扩展密钥用途、用来给软件做数字签名，让用户能核实发布者身份和文件完整性的 X.509 证书。
- [证书颁发机构](https://ssl.sh/zh/glossary/certificate-authority/): 证书颁发机构（CA）是负责审核申请者、签发数字证书，并把公钥与域名或身份绑定在一起的机构。
- [PKI](https://ssl.sh/zh/glossary/pki/): PKI 即公钥基础设施，指用于签发、分发、验证和吊销数字证书的一整套角色、策略、软件和操作流程。
- [SSL 卸载](https://ssl.sh/zh/glossary/ssl-offloading/): SSL 卸载是把 TLS 握手和加解密的计算工作从应用服务器转移到专门的代理、负载均衡或硬件设备上。
- [KEY 文件](https://ssl.sh/zh/glossary/key-file/): KEY 文件是按惯例存放私钥的 .key 文件，通常为 PEM 编码，但扩展名本身并不说明里面的具体格式。
