encryptRsaOaep
Encrypt a small message with an RSA-OAEP public key.
ts
function encryptRsaOaep(
publicKey: CryptoKey,
plaintext: Uint8Array,
_: unknown,
): Promise<EncryptRsaOaepResult>Parameters
publicKey:CryptoKeyplaintext:Uint8Array_:unknown
See also
encryptRsaOaepOrThrowfor the throwing variant
Examples
ts
const keys = await generateKeyPair({ kind: 'rsa', scheme: 'oaep' });
const encrypted = await encryptRsaOaep(keys.publicKey, plaintext);
if (!encrypted.ok) {
// encrypted.code: 'invalid_key' | 'message_too_long'
throw new Error(encrypted.message);
}
const ciphertext = encrypted.value;