PKI-Lite - v1.0.5
    Preparing search index...

    Cryptographic provider implementation using the Web Crypto API.

    This provider leverages the browser's native Web Crypto API for cryptographic operations, offering excellent performance and security. It supports modern algorithms including RSA, ECDSA, AES, and SHA hashes. The Web Crypto API is available in both browsers and Node.js (16+), making this provider suitable for cross-platform applications.

    Supported operations:

    • Hashing: SHA-1, SHA-256, SHA-384, SHA-512 (MD5 not supported)
    • Asymmetric: RSA-PKCS1, RSA-PSS, RSA-OAEP, ECDSA, ECDH
    • Symmetric: AES-GCM, AES-CBC, AES-CTR
    • Key derivation: PBKDF2, HKDF
    const provider = new WebCryptoProvider()

    // Hash data
    const hash = await provider.digest(data, 'SHA-256')

    // Sign data with RSA-PSS
    const signature = await provider.sign(
    data,
    privateKeyInfo,
    { type: 'RSA_PSS', params: { hash: 'SHA-256', saltLength: 32 } }
    )

    // Encrypt with AES-GCM
    const encrypted = await provider.encryptSymmetric(
    plaintext,
    key,
    { type: 'AES_GCM', params: { iv: iv, tagLength: 16 } }
    )

    Hierarchy (View Summary)

    Implements

    Index

    Constructors

    Properties

    crypto: { subtle: SubtleCrypto } = globalThis.crypto

    Reference to the Web Crypto API interface. Protected to allow testing with mock implementations.

    Methods

    • Converts symmetric encryption algorithm parameters to a content encryption algorithm identifier.

      Parameters

      • encryptionParams:
            | SymmetricEncryptionAlgorithmParams
            | {
                params: {
                    derivationAlgorithm: {
                        params: {
                            hash: HashAlgorithm;
                            iterationCount: number;
                            keyLength?: number;
                            salt: Uint8Array;
                        };
                        type: "PBKDF2";
                    };
                    encryptionAlgorithm: SymmetricEncryptionAlgorithmParams;
                };
                type: "PBES2";
            }

        The symmetric encryption algorithm parameters

      Returns AlgorithmIdentifier

      Content encryption algorithm as an AlgorithmIdentifier

    • Decrypts the given data using the specified symmetric key and algorithm.

      Parameters

      • data: Uint8Array

        The data to decrypt

      • key: string | Uint8Array<ArrayBufferLike> | CryptoKey

        The symmetric key to use for decryption

      • algorithm:
            | SymmetricEncryptionAlgorithmParams
            | {
                params: {
                    derivationAlgorithm: {
                        params: {
                            hash: HashAlgorithm;
                            iterationCount: number;
                            keyLength?: number;
                            salt: Uint8Array;
                        };
                        type: "PBKDF2";
                    };
                    encryptionAlgorithm: SymmetricEncryptionAlgorithmParams;
                };
                type: "PBES2";
            }

        The decryption algorithm to use

      Returns Promise<Uint8Array<ArrayBufferLike>>

      Promise resolving to the decrypted data as a Uint8Array

    • Parameters

      • password: string | Uint8Array<ArrayBufferLike> | CryptoKey
      • algorithm: {
            params: {
                derivationAlgorithm: {
                    params: {
                        hash: HashAlgorithm;
                        iterationCount: number;
                        keyLength?: number;
                        salt: Uint8Array;
                    };
                    type: "PBKDF2";
                };
                encryptionAlgorithm: SymmetricEncryptionAlgorithmParams;
            };
            type: "PBES2";
        }

      Returns Promise<CryptoKey>

    • Derives a cryptographic key from a password using the specified algorithm.

      Parameters

      • password: string | Uint8Array<ArrayBufferLike> | CryptoKey

        The password or key material to derive from

      • algorithm: {
            params: {
                derivationAlgorithm: {
                    params: {
                        hash: HashAlgorithm;
                        iterationCount: number;
                        keyLength?: number;
                        salt: Uint8Array;
                    };
                    type: "PBKDF2";
                };
                encryptionAlgorithm: SymmetricEncryptionAlgorithmParams;
            };
            type: "PBES2";
        }

        The key derivation algorithm parameters

      Returns Promise<Uint8Array<ArrayBufferLike>>

      Promise resolving to the derived key as a Uint8Array

    • Encrypts the given data using the specified symmetric key and algorithm.

      Parameters

      • data: Uint8Array

        The data to encrypt

      • key: string | Uint8Array<ArrayBufferLike> | CryptoKey

        The symmetric key to use for encryption

      • algorithm:
            | SymmetricEncryptionAlgorithmParams
            | {
                params: {
                    derivationAlgorithm: {
                        params: {
                            hash: HashAlgorithm;
                            iterationCount: number;
                            keyLength?: number;
                            salt: Uint8Array;
                        };
                        type: "PBKDF2";
                    };
                    encryptionAlgorithm: SymmetricEncryptionAlgorithmParams;
                };
                type: "PBES2";
            }

        The encryption algorithm to use

      Returns Promise<Uint8Array<ArrayBufferLike>>

      Promise resolving to the encrypted data as a Uint8Array

    • Generates an asymmetric key pair for the specified algorithm and options.

      Parameters

      • options: {
            algorithm: "RSA" | "EC";
            hash?: string;
            keySize?: number;
            namedCurve?: string;
            publicExponent?: Uint8Array<ArrayBufferLike>;
        }

        Configuration options including algorithm, key size, and other parameters

      Returns Promise<{ privateKey: Uint8Array; publicKey: Uint8Array }>

      A Promise that resolves to an object containing the public and private keys

    • Parameters

      • algorithm: {
            params: {
                hash: HashAlgorithm;
                iterationCount: number;
                keyLength?: number;
                salt: Uint8Array;
            };
            type: "PBKDF2";
        }

      Returns Pbkdf2Params

    • Parameters

      • algorithm:
            | "PBES2"
            | "AES_128_GCM"
            | "AES_192_GCM"
            | "AES_256_GCM"
            | "AES_128_CCM"
            | "AES_192_CCM"
            | "AES_256_CCM"
            | "AES_128_CBC"
            | "AES_192_CBC"
            | "AES_256_CBC"
            | "AES_128_ECB"
            | "AES_192_ECB"
            | "AES_256_ECB"

      Returns AesDerivedKeyParams

    • Parameters

      Returns {
          params: {
              derivationAlgorithm: {
                  params: {
                      hash: HashAlgorithm;
                      iterationCount: number;
                      keyLength?: number;
                      salt: Uint8Array;
                  };
                  type: "PBKDF2";
              };
              encryptionAlgorithm: SymmetricEncryptionAlgorithmParams;
          };
          type: "PBES2";
      }