Skip to main content
softhsm2-migrate migrates token databases from SoftHSM v1 to SoftHSM v2 via the PKCS#11 interface. By default it targets libsofthsm2, but any PKCS#11 library can be used via --module.
softhsm2-migrate is only available when SoftHSM v2 is built with SQLite3 support (./configure --with-migrate). The SoftHSM v1 database is a SQLite3 file whose location is defined in the v1 configuration file.
softhsm2-migrate --db path --token label [--pin PIN --no-public-key]

Options

--db path
string
required
Path to the SoftHSM v1 SQLite3 database file that will be migrated. The location of this file is specified in the SoftHSM v1 configuration.
--token label
string
Migrate objects into the SoftHSM v2 token whose label matches label. Use this or --slot or --serial to identify the destination token.
--slot number
number
Migrate objects into the token at the specified slot number.
--serial number
string
Migrate objects into the token whose serial number matches number.
--pin PIN
string
The user PIN for the destination SoftHSM v2 token. Required when migrating private key objects.
--no-public-key
flag
Do not migrate public key objects. Only private keys and other objects are imported into the v2 token.
--module path
string
Use an alternative PKCS#11 library instead of the default SoftHSM v2 library.
--help, -h
flag
Show the help screen.
--version, -v
flag
Show version info.

Example

Migrate a v1 database into an existing v2 token named mytoken:
softhsm2-migrate --db /home/user/token.db --token mytoken

Migration workflow

1

Locate the SoftHSM v1 database

Find the database path in your SoftHSM v1 configuration file (typically /etc/softhsm/softhsm.conf). Look for the directories.tokendir or 0: token entry.
2

Initialize a SoftHSM v2 token

Create the destination token in v2 before migrating:
softhsm2-util --init-token --free --label "mytoken" \
  --so-pin 1234 --pin 5678
3

Run the migration

Point --db at the v1 database file and --token at the v2 token label:
softhsm2-migrate --db /home/user/token.db \
  --token mytoken --pin 5678
4

Verify the migrated objects

Use softhsm2-util --show-slots to confirm the token is visible, then verify your application can access the migrated keys through the PKCS#11 interface.

See also

  • softhsm2-util — token management and key import
  • softhsm2-keyconv — key format conversion
  • softhsm2.conf(5) — SoftHSM v2 configuration reference

Build docs developers (and LLMs) love