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);

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);

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");

Generate a new RSA_OAEP keypair

example
const keyPair = await RSA_OAEP.generateKey();

Generate a new RSA_OAEP keypair

alias

generateKey

example
const keyPair = await RSA_OAEP.generateKeyPair();

Import an RSA_OAEP public or private key

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

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 },
);

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});