@nfen/webcrypto-ts
Version:
Enforced Webcrypto wrapper
112 lines • 4.42 kB
TypeScript
/**
* Code related to RSA_OAEP
* @module
*/
import { KeyUsagePairs } from "../key_usages.js";
import * as params from "../params.js";
import { RsaOaepPrivCryptoKey, RsaOaepProxiedCryptoKeyPair, RsaOaepProxiedPrivCryptoKey, RsaOaepProxiedPubCryptoKey, RsaOaepPubCryptoKey } from "./shared.js";
/**
* Generate a new RSA_OAEP keypair
* @example
* ```ts
* const keyPair = await RSA_OAEP.generateKey();
* ```
*/
export declare const generateKey: (algorithm?: Omit<params.EnforcedRsaHashedKeyGenParams, "name">, extractable?: boolean, keyUsages?: KeyUsage[]) => Promise<RsaOaepProxiedCryptoKeyPair>;
/**
* Generate a new RSA_OAEP keypair
* @alias generateKey
* @example
* ```ts
* const keyPair = await RSA_OAEP.generateKeyPair();
* ```
*/
export declare const generateKeyPair: (algorithm?: Omit<params.EnforcedRsaHashedKeyGenParams, "name">, extractable?: boolean, keyUsages?: KeyUsage[]) => Promise<RsaOaepProxiedCryptoKeyPair>;
/**
* Import an RSA_OAEP public or private key
* @example
* ```ts
* const key = await RSA_OAEP.importKey("jwk", pubKey, { hash: "SHA-512" }, true, ['encrypt']);
* ```
*/
export declare const importKey: (format: KeyFormat, key: BufferSource | JsonWebKey, algorithm: Omit<params.EnforcedRsaHashedImportParams, "name">, extractable?: boolean, keyUsages?: KeyUsage[]) => Promise<RsaOaepProxiedPrivCryptoKey | RsaOaepProxiedPubCryptoKey>;
/**
* Export an RSA_OAEP public or private key
* @example
* ```ts
* const pubKeyJwk = await RSA_OAEP.exportKey("jwk", keyPair.publicKey.self);
* ```
* @example
* ```ts
* const pubKeyJwk = await keyPair.publicKey.exportKey("jwk");
* const privKeyJwk = await keyPair.privateKey.exportKey("jwk");
* ```
*/
export declare const exportKey: (format: KeyFormat, key: RsaOaepPrivCryptoKey | RsaOaepPubCryptoKey) => Promise<ArrayBuffer | JsonWebKey>;
/**
* Encrypt with an RSA_OAEP public key
* @example
* ```ts
* const message = new TextEncoder().encode("a message");
* const data = await RSA_OAEP.encrypt({label}, keyPair.publicKey.self, message);
* ```
* @example
* ```ts
* const message = new TextEncoder().encode("a message");
* const data = await keyPair.publicKey.encrypt({label}, message);
* ```
*/
export declare function encrypt(algorithm: Omit<params.EnforcedRsaOaepParams, "name"> | undefined, key: RsaOaepPubCryptoKey, data: BufferSource): Promise<ArrayBuffer>;
/**
* Decrypt with an RSA_OAEP private key
* @example
* ```ts
* const data = await RSA_OAEP.decrypt({label}, keyPair.privateKey.self, data);
* ```
* @example
* ```ts
* const data = await keyPair.privateKey.decrypt({label}, data);
* ```
*/
export declare function decrypt(algorithm: Omit<params.EnforcedRsaOaepParams, "name"> | undefined, key: RsaOaepPrivCryptoKey, data: BufferSource): Promise<ArrayBuffer>;
/**
* Wrap another key with an RSA_OAEP public key
* @example
* ```ts
* 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
* ```ts
* 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});
* ```
*/
export declare function wrapKey(format: KeyFormat, key: CryptoKey, wrappingkey: RsaOaepPubCryptoKey, wrapAlgorithm?: Omit<params.EnforcedRsaOaepParams, "name">): Promise<ArrayBuffer>;
/**
* Unwrap a wrapped key using the key encryption key
* @example
* ```ts
* 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,
* );
* ```
* ```ts
* const wrappedKey = await kek.wrapKey("raw", dek.self);
* const unwrappedKey = await kek.unwrapKey(
* "raw",
* wrappedKey,
* { name: Alg.Mode.RSA_OAEP },
* );
* ```
*/
export declare function unwrapKey(format: KeyFormat, wrappedKey: BufferSource, wrappedKeyAlgorithm: params.EnforcedImportParams, unwrappingKey: RsaOaepPrivCryptoKey, unwrappingKeyAlgorithm: Omit<params.EnforcedRsaOaepParams, "name">, extractable?: boolean, keyUsages?: KeyUsagePairs): Promise<CryptoKey>;
//# sourceMappingURL=rsa_oaep.d.ts.map