Function generateKeypairPEM

  • generate keypair as PEM keys

    Parameters

    • alg: "RSA" | "EC"

      key algorithm (RSA or EC)

    • Optional opt1: string | number

      RSA key length or EC curve name (P-{256,384,512}) RSA key length default is 2048 and EC curve name default is "P-256"

    • Optional opt2: string

      RSA public exponent as hexadecimal string. The default is "010001" (i.e. 65537)

    Returns Promise<string[]>

    Array of private key PEM and public key PEM

    See

    generateKeypairJWK

    Description

    This function generates a RFC 7517 JSON Web Key (JWK) RSA or EC key pair by W3C Web Crypto API.

    Example

    await generateKeyPairPEM("RSA") ->
    ["-----BEGIN PRIVATE...", "-----BEGIN PUBLIC..."] // RSA 2048bit and "010001" public exponent
    await generateKeyPairPEM("RSA", 4096, "0101") ->
    ["-----BEGIN PRIVATE...", "-----BEGIN PUBLIC..."] // RSA 4096bit and "0101" public exponent
    await generateKeyPairPEM("EC") ->
    ["-----BEGIN PRIVATE...", "-----BEGIN PUBLIC..."] // P-256 as default
    await generateKeyPairPEM("EC", "P-521") ->
    ["-----BEGIN PRIVATE...", "-----BEGIN PUBLIC..."] // P-521