Skip to content

importEncryptedPkcs8DerOrThrow ​

importEncryptedPkcs8DerOrThrow ​

Import a private key from DER-encoded PBES2-encrypted PKCS#8 EncryptedPrivateKeyInfo.

Decrypts the PBES2 envelope using the provided password, then imports the key.

When algorithm is omitted, it is inferred from the decrypted key's own privateKeyAlgorithm (see importPkcs8DerOrThrow).

ts
function importEncryptedPkcs8DerOrThrow(
	der: Uint8Array,
	password: string,
	algorithm?: PrivateKeyImportInput,
	options?: ImportEncryptedKeyOptions,
): Promise<CryptoKey>

Parameters

  • der: Uint8Array — DER-encoded EncryptedPrivateKeyInfo bytes
  • password: string — Decryption password
  • algorithm?: PrivateKeyImportInput — Optional expected algorithm; must match decrypted key when given
  • options?: ImportEncryptedKeyOptions — KDF work-factor limit

Throws

  • Error — If DER is malformed, password is wrong, the PBKDF2 iteration count exceeds options.maxKdfIterations, or algorithm doesn't match

See also

Released under the MIT License.