deno.com
method SubtleCrypto.importKey
#SubtleCrypto.importKey(
format: "jwk",
keyData: JsonWebKey,
extractable: boolean,
keyUsages: KeyUsage[],
): Promise<CryptoKey>

Imports a cryptographic key in JSON Web Key (JWK) format.

This method is used to import an asymmetric key (e.g., RSA or ECDSA) from a JWK object. JWK allows structured representation of keys, making them portable across different systems.

Examples #

#
// Import an ECDSA private signing key where `jwk` is an object describing a private key
crypto.subtle.importKey(
  "jwk",
  jwk,
  {
    name: "ECDSA",
    namedCurve: "P-384",
  },
  true,
  ["sign"],
);

Parameters #

#format: "jwk"
#keyData: JsonWebKey
#extractable: boolean
#keyUsages: KeyUsage[]

Return Type #

Promise<CryptoKey>

See #

#SubtleCrypto.importKey(
format: Exclude<KeyFormat, "jwk">,
keyData: BufferSource,
extractable: boolean,
keyUsages: KeyUsage[],
): Promise<CryptoKey>

Imports a cryptographic key in raw, PKCS8, or SPKI format.

This method is used to import symmetric keys (e.g., AES), private keys (PKCS8), or public keys (SPKI).

Examples #

#
// Import an AES-GCM secret key where `rawKey` is an ArrayBuffer string
crypto.subtle.importKey("raw", rawKey, "AES-GCM", true, [
  "encrypt",
  "decrypt",
]);

Parameters #

#format: Exclude<KeyFormat, "jwk">
#keyData: BufferSource
#extractable: boolean
#keyUsages: KeyUsage[]

Return Type #

Promise<CryptoKey>

See #