importPrivateKey(privateKey: string,options?: ImportPrivateKeyOptions): Promise<CryptoKey>
Imports an x25519 private key as a CryptoKey by wrapping it in PKCS8 format.
This function wraps raw 32-byte x25519 private keys in the PKCS8 container format required by the Web Crypto API. The PKCS8 wrapper includes the algorithm OID and proper ASN.1 structure.
options: ImportPrivateKeyOptions
Configuration options for key import
Promise<CryptoKey>
A promise resolving to the imported CryptoKey
importPrivateKey(privateKey: Uint8Array,options?: ImportPrivateKeyOptions): Promise<CryptoKey>
Imports an x25519 private key as a CryptoKey by wrapping it in PKCS8 format.
This function wraps raw 32-byte x25519 private keys in the PKCS8 container format required by the Web Crypto API. The PKCS8 wrapper includes the algorithm OID and proper ASN.1 structure.
Import private key from Uint8Array
Import private key from Uint8Array
import { assertEquals } from "@std/assert"; import { importPrivateKey, randomPrivateKeyBytes } from "@hertzg/wg-keys"; const privateKeyBytes = randomPrivateKeyBytes(); const cryptoKey = await importPrivateKey(privateKeyBytes); assertEquals(cryptoKey.type, "private");
Import private key with custom key usages
Import private key with custom key usages
import { assertEquals } from "@std/assert"; import { importPrivateKey, randomPrivateKeyBytes } from "@hertzg/wg-keys"; const privateKeyBytes = randomPrivateKeyBytes(); const cryptoKey = await importPrivateKey(privateKeyBytes, { keyUsages: ["deriveKey", "deriveBits"], }); assertEquals(cryptoKey.type, "private"); assertEquals(cryptoKey.usages.length, 2);
privateKey: Uint8Array
The 32-byte private key as Uint8Array
options: ImportPrivateKeyOptions
Configuration options for key import
Promise<CryptoKey>
A promise resolving to the imported CryptoKey