Cryptographic key management is the foundation of any security infrastructure. Whether you’re running a private PKI, encrypting database columns, signing code releases, or securing TLS certificates, the keys that protect your data need to be stored, rotated, and accessed securely. Hardware Security Modules (HSMs) provide tamper-resistant key storage — but dedicated hardware HSMs cost thousands of dollars and require specialized infrastructure.
This guide explores three open-source, self-hosted alternatives for cryptographic key management: SoftHSM (software-based PKCS#11 implementation), netHSM (Nitrokey’s network-attached HSM), and PKCS#11 infrastructure tools for building a software key management layer. These solutions provide HSM-like functionality at zero or low cost, suitable for development, testing, and production environments that don’t require FIPS 140-2 Level 3 certification.
What Is an HSM and Why Self-Host One?
A Hardware Security Module (HSM) is a dedicated device that generates, stores, and manages cryptographic keys. Keys never leave the HSM in plaintext — all cryptographic operations (encryption, decryption, signing, verification) happen inside the device. This prevents key extraction even if the host system is compromised.
Reasons to self-host a software or lightweight HSM:
- Cost: Hardware HSMs (Thales Luna, AWS CloudHSM, Azure Dedicated HSM) cost $5,000-$50,000+. Software alternatives are free
- Development and testing: Reproduce production key management workflows without expensive hardware
- Compliance: Meet regulatory requirements for key separation and access control
- Key lifecycle management: Automated key generation, rotation, and destruction
- Multi-tenant key isolation: Separate key stores for different applications or teams
SoftHSM
SoftHSM is a software implementation of a PKCS#11 cryptographic token, maintained by the OpenDNSSEC project. With over 1,017 GitHub stars and active development, it’s the most widely used open-source software HSM.
SoftHSM implements the PKCS#11 API (Cryptoki), allowing any PKCS#11-compatible application to use it as a key store. It supports RSA, ECDSA, AES, DES, and SHA algorithms, with keys stored in encrypted files on disk.
Docker Deployment
| |
Initialize a Token
| |
Configuration File
| |
Integration with OpenSSL
SoftHSM can be used with OpenSSL via the PKCS#11 engine:
| |
Key Features
- Full PKCS#11 v2.40 API implementation
- Support for RSA, ECDSA, DSA, AES, DES, SHA-1/256/384/512
- Multiple token (slot) support for key isolation
- PIN-based access control with SO (Security Officer) and User PINs
- Encrypted token storage on disk
- Compatible with OpenSSL, GnuTLS, and any PKCS#11 application
netHSM
netHSM is Nitrokey’s open-source network-attached HSM. Unlike SoftHSM (pure software), netHSM is designed to run on dedicated hardware (Raspberry Pi CM4 with a secure element) but can also run as a software container for development. It provides a REST API for key management, making it accessible from any programming language.
With 100 GitHub stars and active development by Nitrokey, netHSM bridges the gap between pure software HSMs and expensive dedicated hardware.
Docker Deployment
| |
Using the REST API
| |
PKCS#11 Module
netHSM also provides a PKCS#11 module for compatibility with existing applications:
| |
Key Features
- REST API for key management (generate, list, use, delete keys)
- PKCS#11 module for backward compatibility
- Support for RSA, ECDSA, Ed25519, AES
- Role-based access control (Administrator, Operator)
- Audit logging of all key operations
- Can run on Raspberry Pi CM4 with Nitrokey secure element for hardware-backed security
PKCS#11 Infrastructure Tools
PKCS#11 (Public-Key Cryptography Standards #11) defines a standard API for cryptographic tokens. Building a PKCS#11-based key management infrastructure involves selecting the right components:
Core Components
- PKCS#11 Provider — the actual cryptographic implementation (SoftHSM, OpenSC, etc.)
- PKCS#11 Tool — command-line management (
pkcs11-toolfrom OpenSC) - PKCS#11 Proxy — network access to local tokens (
p11-proxy) - Application Integration — OpenSSL engine, GnuTLS PKCS#11 support
OpenSC pkcs11-tool
| |
p11-kit — Unified PKCS#11 Module Loading
| |
Comparison Table
| Feature | SoftHSM | netHSM | PKCS#11 Infrastructure |
|---|---|---|---|
| Type | Software HSM | Network HSM | API standard + tools |
| GitHub Stars | 1,017 | 100 | N/A (standard) |
| Last Update | May 2026 | March 2026 | Ongoing |
| PKCS#11 Support | Native | Via module | The standard itself |
| REST API | No | Yes | No |
| Hardware Backing | No | Optional (RPi CM4 + SE) | Depends on provider |
| Algorithms | RSA, ECDSA, DSA, AES, DES | RSA, ECDSA, Ed25519, AES | Provider-dependent |
| Key Storage | Encrypted files | Encrypted database | Provider-dependent |
| Multi-tenant | Via multiple slots | Via role-based access | Via multiple tokens |
| Audit Logging | Basic (syslog) | Built-in | Provider-dependent |
| Docker Support | Community images | Official GHCR image | Various |
| Cost | Free | Free (software), ~$50 (hardware) | Free |
| Best For | Dev/test, small production | Teams needing API access | Custom key management |
Which Should You Choose?
Choose SoftHSM if:
- You need a pure software HSM for development and testing
- You want the most mature and widely supported open-source PKCS#11 implementation
- Your applications already support PKCS#11 (OpenSSL, GnuTLS, Java JCE)
- You don’t need network-accessible key management
Choose netHSM if:
- You want a REST API for programmatic key management
- You need role-based access control (Administrator vs Operator roles)
- You want the option to upgrade to hardware-backed security later
- You’re building a multi-tenant key management service
Choose a PKCS#11 Infrastructure approach if:
- You need to support multiple HSM vendors with a single application interface
- You want to build a custom key management layer on top of standard APIs
- You need fine-grained control over cryptographic operations
- You’re integrating with existing PKCS#11-compatible applications
Why Self-Host Your Key Management Infrastructure?
Cloud-based key management services (AWS KMS, Azure Key Vault, Google Cloud KMS) are convenient but create vendor lock-in and require trust in the cloud provider. Self-hosted HSMs give you full control over key generation, storage, and access policies.
For organizations with compliance requirements (PCI DSS, FIPS 140-2), self-hosted key management ensures keys never leave your infrastructure boundary. Even software HSMs like SoftHSM provide cryptographic isolation that plaintext key files cannot match.
For secrets management alongside key management, the HashiCorp Vault vs Infisical vs Passbolt guide covers application secrets rotation. For certificate automation, the cert-manager vs Lego vs ACME.sh guide covers automated TLS certificate management.
FAQ
What is the difference between an HSM and a key management system?
An HSM (Hardware Security Module) is a physical or virtual device that generates, stores, and uses cryptographic keys. Keys never leave the HSM in plaintext. A Key Management System (KMS) is a broader concept that may include key generation, rotation, backup, and access policy management — it may or may not use an HSM as the underlying key store.
Can SoftHSM be used in production?
SoftHSM is suitable for production use cases that don’t require FIPS 140-2 Level 3 certification. It provides encrypted key storage on disk and PIN-based access control. However, since it runs in software, keys are potentially accessible to anyone with root access to the host system. For high-security environments, a hardware-backed HSM is recommended.
How do I migrate keys from SoftHSM to a hardware HSM?
Keys generated in SoftHSM cannot be directly exported to a hardware HSM because HSMs are designed to prevent key extraction. The recommended approach is to generate new keys on the target HSM and update your applications to reference the new key identifiers. For certificate-based workflows, you’ll need to reissue certificates with the new keys.
What algorithms does netHSM support?
netHSM supports RSA (1024-4096 bit), ECDSA (P-256, P-384, P-521), Ed25519, and AES (128, 256 bit). The supported mechanisms depend on the underlying cryptographic library and can be extended through firmware updates.
How do I backup SoftHSM tokens?
SoftHSM tokens are stored as files in the token directory (configured via directories.tokendir in softhsm2.conf). Back up this directory regularly. The token files are encrypted with the SO PIN, so ensure you have the PIN available for restoration. Test your backup and restore procedure in a non-production environment.
Can multiple applications share the same SoftHSM token?
Yes, multiple applications can access the same SoftHSM token simultaneously using the same PKCS#11 module path. Each application authenticates with the User PIN. For key isolation between applications, create separate tokens (slots) with different PINs.
How does netHSM compare to AWS CloudHSM?
netHSM is an open-source, self-hosted alternative to AWS CloudHSM. While CloudHSM provides FIPS 140-2 Level 3 certified hardware, netHSM offers similar functionality (REST API, key generation, signing) at a fraction of the cost. netHSM on Raspberry Pi hardware with a secure element provides a reasonable middle ground for organizations that need some hardware backing without the $5,000+ cost of certified HSMs.