Skip to content

Add Build TR-31 Key Block operation #3

@J8k3

Description

@J8k3

Feature request

Parse TR-31 Key Block decodes an existing key block. We need the complement: a Build TR-31 Key Block operation that assembles a valid TR-31 key block header from structured inputs, optionally wrapping a provided payload.

Proposed scope

Header construction (always):

  • Version ID selector (A / B / C / D) with descriptions — default D
  • Key usage dropdown — all X9.143 codes with human-readable descriptions (same table now in ParseTR31KeyBlock.mjs)
  • Algorithm selector (A=AES, T=Triple DEA, R=RSA, E=EC, H=HMAC, S=DSA)
  • Mode of use selector (B/C/D/E/G/N/S/T/V/X/Y) with descriptions
  • Key version number (2 chars, default 00)
  • Exportability selector (E / N / S) with descriptions
  • Optional blocks: label (LB), key block ID (BI), KCV (KC)

Body wrapping (optional):
If a pre-encrypted payload is provided as input, append it after the header so the output is a complete TR-31 key block string. If no payload is provided, output the 16-character header only.

Why useful

Quick assembly and validation of TR-31 key block headers without needing a full HSM or TR-31 library. Useful for testing parsers, verifying field encoding, and building synthetic test vectors. Mirrors how Build PIN Block complements Parse PIN Block.

Implementation notes

  • File: src/core/operations/BuildTR31KeyBlock.mjs, module Payment
  • Header length field (chars 1–4) must be the total block length including body; when no body is provided, emit the 16-char header with length 0016
  • Validate that the selected (algorithm, key usage) combination is PCI-compliant and emit a warning if not (e.g., Single DES, TDES PIN key)
  • Optional block length encoding: 2-char block ID + 2-char decimal length + value

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions