Function importPEM

  • import key from PEM private/public key string

    Parameters

    • pem: string

      PEM PKCS#8 private key or public key string

    • alg: string

      signature algorithm (SHA{1,224,256,384,512}with{RSA,RSAandMGF1,ECDSA})

    • Optional sigopt: string | number

      saltLength for RSA-PSS

    Returns Promise<CryptoKey>

    CryptoKey object of W3C Web Crypto API

    See

    https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey

    Description

    This function import a CryptoKey object from PEM key file.
    NOTE: For EC key, namedCurve value will be automatically detected by PEM file. So no need to specify.

    Example

    key = await importPEM("-----BEGIN PRIVATE...", "SHA256withRSA");
    key = await importPEM("-----BEGIN PUBLIC...", "SHA256withECDSA");
    key = await importPEM("-----BEGIN PRIVATE...", "SHA256withRSAandMGF1");