Crypto KMS
    Preparing search index...

    Class Pkcs11HsmProvider

    Simulated PKCS#11 KMS provider.

    An in-memory software simulation of a PKCS#11-style provider for tests and CI. It has no hardware backing, no key isolation and no FIPS 140 validation. Construction requires simulate: true and throws otherwise.

    const hsm = new Pkcs11HsmProvider({
    simulate: true,
    hsmModel: "thales-luna",
    tokenLabel: "Institutional-Vault-01",
    pin: "123456",
    });
    const key = await hsm.createKey("aes-256-gcm", "encrypt");
    const { ciphertext } = await hsm.encrypt(key.keyId, new TextEncoder().encode("secret"));

    Implements

    Index
    name: "pkcs11"

    Provider identifier.

    hsmModel: string

    HSM model label (diagnostic only; no device is contacted).

    slotIndex: number

    Configured slot index.

    tokenLabel: string

    Configured token label.

    • Create a key held in process memory (not hardware-isolated).

      Parameters

      • algorithm: string
      • usage: "encrypt" | "sign" | "wrap"
      • Optional_metadata: Record<string, string>

      Returns Promise<KmsKeyMetadata>

    • Schedule deletion of a simulated key.

      Parameters

      • keyId: string
      • pendingWindowDays: number = 7

      Returns Promise<void>

    • Encrypt plaintext with AES-256-GCM in software (current key version).

      Parameters

      • keyId: string
      • plaintext: Uint8Array
      • Optionalcontext: Record<string, string>

      Returns Promise<KmsEncryptResult>

    • Decrypt ciphertext with AES-256-GCM using the key version it names.

      Parameters

      • keyId: string
      • ciphertext: string
      • Optionalcontext: Record<string, string>

      Returns Promise<KmsDecryptResult>

    • Sign data with Ed25519 in software (current key version).

      Parameters

      • keyId: string
      • data: Uint8Array
      • algorithm: string = "Ed25519"

      Returns Promise<KmsSignResult>

    • Verify a signature against every simulated key version that has not been destroyed. Malformed signatures verify as false.

      Parameters

      • keyId: string
      • data: Uint8Array
      • signature: string
      • Optional_algorithm: string

      Returns Promise<boolean>

    • Destroy the material of a non-current key version. Rejects with INVALID_ARGUMENT for the current version and NOT_FOUND for an unknown key or version.

      Parameters

      • keyId: string
      • version: number

      Returns Promise<void>

    • Generate a data encryption key wrapped by the simulated key.

      Parameters

      • keyId: string
      • _keySpec: string = "AES_256"

      Returns Promise<{ plaintext: Uint8Array; ciphertext: string }>