@nfen/webcrypto-ts
Version:
Enforced Webcrypto wrapper
96 lines • 2.71 kB
TypeScript
import { AesProxiedCryptoKeys } from "../aes/shared.js";
import { HmacProxiedCryptoKey } from "../hmac/index.js";
import * as params from "../params.js";
import { Pbkdf2KeyMaterial, Pbkdf2ProxiedKeyMaterial } from "./shared.js";
/**
* Generate key material for deriving
* @example
* ```ts
* const keyMaterial = await PBKDF2.generateKeyMaterial("raw", new TextEncoder().encode("could_be_a_little_entropy"));
* ```
*/
export declare const generateKeyMaterial: (format: KeyFormat, key: BufferSource, extractable?: boolean) => Promise<Pbkdf2ProxiedKeyMaterial>;
/**
* Derive a shared key from PBKDF2 key material
* @example
* ```ts
* const hmacParams: params.EnforcedHmacKeyGenParams = {
* name: Authentication.Alg.Code.HMAC,
* hash: SHA.Alg.Variant.SHA_512,
* length: 512,
* };
* let key = await PBKDF2.deriveKey(
* { hash: "SHA512" },
* keyMaterial,
* hmacParams
* );
* ```
* @example
* ```ts
* const hmacParams: params.EnforcedHmacKeyGenParams = {
* name: Authentication.Alg.Code.HMAC,
* hash: SHA.Alg.Variant.SHA_512,
* length: 512,
* };
* const keyMaterial = await PBKDF2.generateKeyMaterial(
* "raw",
* await Random.getValues(16)
* );
* let key = await keyMaterial.deriveKey(
* { hash: "SHA512" },
* hmacParams
* );
* ```
* @example
* ```ts
* const keyMaterial = await PBKDF2.generateKeyMaterial(
* "raw",
* await Random.getValues(16)
* );
* let key = await PBKDF2.deriveKey(
* {
* hash: "SHA-256",
* salt,
* },
* keyMaterial.self,
* {
* name: "AES-GCM",
* length: 256,
* }
* );
* ```
* @example
* ```ts
* const key = await keyMaterial.deriveKey(
* {
* hash: "SHA-256",
* salt,
* },
* {
* name: "AES-GCM",
* length: 256,
* }
* );
* ```
*/
export declare const deriveKey: (algorithm: Omit<params.EnforcedPbkdf2Params, "name" | "iterations">, baseKey: Pbkdf2KeyMaterial, derivedKeyType: params.EnforcedAesKeyGenParams | params.EnforcedHmacKeyGenParams, extractable?: boolean, keyUsages?: KeyUsage[]) => Promise<HmacProxiedCryptoKey | AesProxiedCryptoKeys>;
/**
* Derive a number bits with a given key material
* @example
* ```ts
* const bits = await PBKDF2.deriveBits(
* { hash: "SHA-512" },
* keyMaterial,
* 128
* );
* ```
* @example
* ```ts
* const bits = await keyMaterial.deriveBits(
* { hash: "SHA-512" },
* 128
* );
* ```
*/
export declare const deriveBits: (algorithm: Omit<params.EnforcedPbkdf2Params, "name" | "iterations">, baseKey: Pbkdf2KeyMaterial, length: number) => Promise<ArrayBuffer>;
//# sourceMappingURL=pbkdf.d.ts.map