Module rsa/rsa_oaep
source · [−]Expand description
Code related to RSA_OAEP
Functions
sourcedecrypt
decrypt
source(algorithm?: Omit<EnforcedRsaOaepParams, "name">, key: RsaOaepPrivCryptoKey, data: BufferSource): Promise<ArrayBuffer>
(algorithm?: Omit<EnforcedRsaOaepParams, "name">, key: RsaOaepPrivCryptoKey, data: BufferSource): Promise<ArrayBuffer>
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
algorithm: Omit<EnforcedRsaOaepParams, "name"> = {}
key: RsaOaepPrivCryptoKey
data: BufferSource
Returns Promise<ArrayBuffer>
sourceencrypt
encrypt
source(algorithm?: Omit<EnforcedRsaOaepParams, "name">, key: RsaOaepPubCryptoKey, data: BufferSource): Promise<ArrayBuffer>
(algorithm?: Omit<EnforcedRsaOaepParams, "name">, key: RsaOaepPubCryptoKey, data: BufferSource): 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
algorithm: Omit<EnforcedRsaOaepParams, "name"> = {}
key: RsaOaepPubCryptoKey
data: BufferSource
Returns Promise<ArrayBuffer>
sourceexportKey
exportKey
source(format: KeyFormat, key: RsaOaepPubCryptoKey | RsaOaepPrivCryptoKey): Promise<ArrayBuffer | JsonWebKey>
(format: KeyFormat, key: RsaOaepPubCryptoKey | RsaOaepPrivCryptoKey): Promise<ArrayBuffer | JsonWebKey>
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
format: KeyFormat
key: RsaOaepPubCryptoKey | RsaOaepPrivCryptoKey
Returns Promise<ArrayBuffer | JsonWebKey>
sourcegenerateKey
generateKey
source(algorithm?: Omit<EnforcedRsaHashedKeyGenParams, "name">, extractable?: boolean, keyUsages?: KeyUsage[]): Promise<RsaOaepProxiedCryptoKeyPair>
(algorithm?: Omit<EnforcedRsaHashedKeyGenParams, "name">, extractable?: boolean, keyUsages?: KeyUsage[]): Promise<RsaOaepProxiedCryptoKeyPair>
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>
sourcegenerateKeyPair
generateKeyPair
source(algorithm?: Omit<EnforcedRsaHashedKeyGenParams, "name">, extractable?: boolean, keyUsages?: KeyUsage[]): Promise<RsaOaepProxiedCryptoKeyPair>
(algorithm?: Omit<EnforcedRsaHashedKeyGenParams, "name">, extractable?: boolean, keyUsages?: KeyUsage[]): 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>
sourceimportKey
importKey
source(format: KeyFormat, key: BufferSource | JsonWebKey, algorithm: Omit<EnforcedRsaHashedImportParams, "name">, extractable?: boolean, keyUsages?: KeyUsage[]): Promise<RsaOaepProxiedPubCryptoKey | RsaOaepProxiedPrivCryptoKey>
(format: KeyFormat, key: BufferSource | JsonWebKey, algorithm: Omit<EnforcedRsaHashedImportParams, "name">, extractable?: boolean, keyUsages?: KeyUsage[]): Promise<RsaOaepProxiedPubCryptoKey | RsaOaepProxiedPrivCryptoKey>
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>
sourceunwrapKey
unwrapKey
source(format: KeyFormat, wrappedKey: BufferSource, wrappedKeyAlgorithm: EnforcedImportParams, unwrappingKey: RsaOaepPrivCryptoKey, unwrappingKeyAlgorithm: Omit<EnforcedRsaOaepParams, "name">, extractable?: boolean, keyUsages?: KeyUsagePairs): Promise<CryptoKey>
(format: KeyFormat, wrappedKey: BufferSource, wrappedKeyAlgorithm: EnforcedImportParams, unwrappingKey: RsaOaepPrivCryptoKey, unwrappingKeyAlgorithm: Omit<EnforcedRsaOaepParams, "name">, extractable?: boolean, keyUsages?: KeyUsagePairs): Promise<CryptoKey>
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
format: KeyFormat
wrappedKey: BufferSource
wrappedKeyAlgorithm: EnforcedImportParams
unwrappingKey: RsaOaepPrivCryptoKey
unwrappingKeyAlgorithm: Omit<EnforcedRsaOaepParams, "name">
extractable: boolean = true
Optional keyUsages: KeyUsagePairs
Returns Promise<CryptoKey>
sourcewrapKey
wrapKey
source(format: KeyFormat, key: CryptoKey, wrappingkey: RsaOaepPubCryptoKey, wrapAlgorithm?: Omit<EnforcedRsaOaepParams, "name">): Promise<ArrayBuffer>
(format: KeyFormat, key: CryptoKey, wrappingkey: RsaOaepPubCryptoKey, wrapAlgorithm?: Omit<EnforcedRsaOaepParams, "name">): Promise<ArrayBuffer>
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
format: KeyFormat
key: CryptoKey
wrappingkey: RsaOaepPubCryptoKey
Optional wrapAlgorithm: Omit<EnforcedRsaOaepParams, "name">