PKI-Lite - v1.2.1
    Preparing search index...

    KeyGen class provides functionality to generate cryptographic key pairs.

    This class leverages the configured cryptographic provider to create key pairs for various algorithms such as RSA, ECDSA, and EdDSA. The generated keys are returned in standard formats suitable for storage and usage in cryptographic operations.

    // Generate an RSA key pair
    const { privateKey, publicKey } = await KeyGen.generate({
    algorithm: 'RSA',
    params: {
    keySize: 2048,
    hash: 'SHA-256'
    }
    })

    // Or use convenience methods
    const rsaPair = await KeyGen.generateRsaPair({ keySize: 2048 })
    const ecPair = await KeyGen.generateEcPair({ namedCurve: 'P-256' })
    Index

    Constructors

    Methods

    • Generates an EC (Elliptic Curve) key pair with the specified curve.

      Parameters

      • Optionaloptions: { namedCurve?: "P-256" | "P-384" | "P-521" }

        EC key generation options (defaults: namedCurve='P-256')

      Returns Promise<{ privateKey: PrivateKeyInfo; publicKey: SubjectPublicKeyInfo }>

      A PrivateKeyInfo containing the generated EC key pair

      // Generate P-256 EC key pair (default)
      const { privateKey, publicKey } = await KeyGen.generateEcPair()

      // Generate P-384 EC key pair
      const { privateKey, publicKey } = await KeyGen.generateEcPair({
      namedCurve: 'P-384'
      })
    • Generates an RSA key pair with the specified options.

      Parameters

      • Optionaloptions: {
            hash?: "SHA-1" | "SHA-256" | "SHA-384" | "SHA-512";
            keySize?: number;
            publicExponent?: number;
        }

        RSA key generation options (defaults: keySize=2048, hash='SHA-256')

      Returns Promise<{ privateKey: PrivateKeyInfo; publicKey: SubjectPublicKeyInfo }>

      A PrivateKeyInfo containing the generated RSA key pair

      // Generate 2048-bit RSA key pair
      const { privateKey, publicKey } = await KeyGen.generateRsaPair()

      // Generate 4096-bit RSA key pair with SHA-512
      const { privateKey, publicKey } = await KeyGen.generateRsaPair({
      keySize: 4096,
      hash: 'SHA-512'
      })