Expand description

Code related to RSA_OAEP

Functions

Decrypt with an RSA_OAEP private key

example
const data = await RSA_OAEP.decrypt({label}, keyPair.privateKey.self, data);
example
const data = await keyPair.privateKey.decrypt({label}, data);

Parameters

Returns Promise<ArrayBuffer>

Encrypt with an RSA_OAEP public key

example
const message = new TextEncoder().encode("a message");
const data = await RSA_OAEP.encrypt({label}, keyPair.publicKey.self, message);
example
const message = new TextEncoder().encode("a message");
const data = await keyPair.publicKey.encrypt({label}, message);

Parameters

Returns Promise<ArrayBuffer>

Export an RSA_OAEP public or private key

example
const pubKeyJwk = await RSA_OAEP.exportKey("jwk", keyPair.publicKey.self);
example
const pubKeyJwk = await keyPair.publicKey.exportKey("jwk");
const privKeyJwk = await keyPair.privateKey.exportKey("jwk");

Parameters

Returns Promise<ArrayBuffer | JsonWebKey>

Generate a new RSA_OAEP keypair

example
const keyPair = await RSA_OAEP.generateKey();

Parameters

  • algorithm: Omit<EnforcedRsaHashedKeyGenParams, "name"> = { hash: SHA.Variant.SHA_512, modulusLength: 4096, publicExponent: new Uint8Array([0x01, 0x00, 0x01]), }
  • Optional extractable: boolean
  • Optional keyUsages: KeyUsage[]

Returns Promise<RsaOaepProxiedCryptoKeyPair>

Generate a new RSA_OAEP keypair

alias

generateKey

example
const keyPair = await RSA_OAEP.generateKeyPair();

Parameters

  • algorithm: Omit<EnforcedRsaHashedKeyGenParams, "name"> = { hash: SHA.Variant.SHA_512, modulusLength: 4096, publicExponent: new Uint8Array([0x01, 0x00, 0x01]), }
  • Optional extractable: boolean
  • Optional keyUsages: KeyUsage[]

Returns Promise<RsaOaepProxiedCryptoKeyPair>

Import an RSA_OAEP public or private key

example
const key = await RSA_OAEP.importKey("jwk", pubKey, { hash: "SHA-512" }, true, ['encrypt']);

Parameters

  • format: KeyFormat
  • key: BufferSource | JsonWebKey
  • algorithm: Omit<EnforcedRsaHashedImportParams, "name">
  • Optional extractable: boolean
  • Optional keyUsages: KeyUsage[]

Returns Promise<RsaOaepProxiedPubCryptoKey | RsaOaepProxiedPrivCryptoKey>

Unwrap a wrapped key using the key encryption key

example
const wrappedKey = await RSA_OAEP.wrapKey("raw", dek.self, kek.self);
const unwrappedKey = await RSA_OAEP.unwrapKey(
"raw",
wrappedKey,
{ name: Alg.Mode.RSA_OAEP },
kek.self,
);
const wrappedKey = await kek.wrapKey("raw", dek.self);
const unwrappedKey = await kek.unwrapKey(
"raw",
wrappedKey,
{ name: Alg.Mode.RSA_OAEP },
);

Parameters

Returns Promise<CryptoKey>

Wrap another key with an RSA_OAEP public key

example
const kek = await RSA_OAEP.generateKey(undefined, true, ['wrapKey', 'unwrapKey']);
const dek = await RSA_OAEP.generateKey();
const label = await Random.getValues(8);
const wrappedKey = await RSA_OAEP.wrapKey("raw", dek.self, kek.self, {label});
example
const kek = await RSA_OAEP.generateKey(undefined, true, ['wrapKey', 'unwrapKey']);
const dek = await RSA_OAEP.generateKey();
const label = await Random.getValues(8);
const wrappedKey = await kek.wrapKey("raw", dek.self, {label});

Parameters

Returns Promise<ArrayBuffer>