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

    Interface defining the cryptographic operations required by the PKI library.

    This interface abstracts cryptographic operations to allow different implementations based on available platforms and algorithm requirements. The default WebCryptoProvider uses the Web Crypto API, while extended providers can support additional algorithms and legacy cryptographic functions.

    Implementations must provide:

    • Hashing operations for message digests
    • Digital signature creation and verification
    • Asymmetric encryption and decryption
    • Symmetric encryption and decryption
    • Key derivation functions
    • Random number generation
    class CustomCryptoProvider implements CryptoProvider {
    async digest(data: Uint8Array, algorithm: HashAlgorithm): Promise<Uint8Array> {
    // Custom hash implementation
    return customHash(data, algorithm)
    }

    // Implement other required methods...
    }

    // Use custom provider
    setCryptoProvider(new CustomCryptoProvider())
    interface CryptoProvider {
        contentEncryptionAlgorithm(
            encryptionParams: SymmetricEncryptionAlgorithmParams,
        ): AlgorithmIdentifier;
        decrypt(
            data: Uint8Array,
            privateKeyInfo: PrivateKeyInfo,
            algorithm: AsymmetricEncryptionAlgorithmParams,
        ): Promise<Uint8Array<ArrayBufferLike>>;
        decryptSymmetric(
            data: Uint8Array,
            key: Uint8Array,
            algorithm:
                | SymmetricEncryptionAlgorithmParams
                | {
                    params: {
                        derivationAlgorithm: {
                            params: {
                                hash: HashAlgorithm;
                                iterationCount: number;
                                keyLength?: number;
                                salt: Uint8Array;
                            };
                            type: "PBKDF2";
                        };
                        encryptionAlgorithm: SymmetricEncryptionAlgorithmParams;
                    };
                    type: "PBES2";
                },
        ): Promise<Uint8Array<ArrayBufferLike>>;
        deriveKey(
            password: string | Uint8Array<ArrayBufferLike>,
            algorithm: {
                params: {
                    derivationAlgorithm: {
                        params: {
                            hash: HashAlgorithm;
                            iterationCount: number;
                            keyLength?: number;
                            salt: Uint8Array;
                        };
                        type: "PBKDF2";
                    };
                    encryptionAlgorithm: SymmetricEncryptionAlgorithmParams;
                };
                type: "PBES2";
            },
        ): Promise<Uint8Array<ArrayBufferLike>>;
        digest(
            data: Uint8Array,
            hash: HashAlgorithm,
        ): Promise<Uint8Array<ArrayBufferLike>>;
        digestAlgorithm(
            algorithm: HashAlgorithm,
        ): Uint8Array<ArrayBufferLike> | AlgorithmIdentifier;
        encrypt(
            data: Uint8Array,
            publicKeyInfo: SubjectPublicKeyInfo,
            algorithm: AsymmetricEncryptionAlgorithmParams,
        ): Promise<Uint8Array<ArrayBufferLike>>;
        encryptSymmetric(
            data: Uint8Array,
            key: Uint8Array,
            algorithm:
                | SymmetricEncryptionAlgorithmParams
                | {
                    params: {
                        derivationAlgorithm: {
                            params: {
                                hash: HashAlgorithm;
                                iterationCount: number;
                                keyLength?: number;
                                salt: Uint8Array;
                            };
                            type: "PBKDF2";
                        };
                        encryptionAlgorithm: SymmetricEncryptionAlgorithmParams;
                    };
                    type: "PBES2";
                },
        ): Promise<Uint8Array<ArrayBufferLike>>;
        generateKeyPair(options: KeyPairGenOptions): Promise<KeyPair>;
        generateSymmetricKey(
            algorithm: SymmetricEncryptionAlgorithmParams,
        ): Uint8Array;
        getEcCurveParameters(
            algorithm: AsymmetricEncryptionAlgorithmParams,
        ): Uint8Array<ArrayBufferLike> | ObjectIdentifier;
        getEcNamedCurve(
            algorithm: AlgorithmIdentifier,
            publicKeyInfo?: SubjectPublicKeyInfo,
        ): NamedCurve;
        getRandomValues(length: number): Uint8Array;
        keyEncryptionAlgorithm(
            encryptionParams: AsymmetricEncryptionAlgorithmParams,
        ): AlgorithmIdentifier;
        sign(
            data: Uint8Array,
            privateKeyInfo: PrivateKeyInfo,
            algorithm: AsymmetricEncryptionAlgorithmParams,
        ): Promise<Uint8Array<ArrayBufferLike>>;
        signatureAlgorithm(
            algorithm: AsymmetricEncryptionAlgorithmParams,
        ): Uint8Array<ArrayBufferLike> | AlgorithmIdentifier;
        toAsymmetricEncryptionAlgorithmParams(
            algorithm: AlgorithmIdentifier,
            publicKeyInfo?: SubjectPublicKeyInfo,
        ): AsymmetricEncryptionAlgorithmParams;
        toHashAlgorithm(algorithm: AlgorithmIdentifier): HashAlgorithm;
        toSymmetricEncryptionAlgorithmParams(
            algorithm: AlgorithmIdentifier,
        ): SymmetricEncryptionAlgorithmParams;
        verify(
            data: Uint8Array,
            publicKeyInfo: SubjectPublicKeyInfo,
            signature: Uint8Array,
            algorithm: AsymmetricEncryptionAlgorithmParams,
        ): Promise<boolean>;
    }

    Implemented by

    Index

    Methods

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

      Parameters

      • data: Uint8Array

        The data to decrypt

      • key: Uint8Array

        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

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

      Parameters

      • password: string | Uint8Array<ArrayBufferLike>

        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

    • Computes the cryptographic hash digest of the given data.

      Parameters

      Returns Promise<Uint8Array<ArrayBufferLike>>

      Promise resolving to the hash digest bytes

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

      Parameters

      • data: Uint8Array

        The data to encrypt

      • key: Uint8Array

        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 cryptographically secure random bytes.

      Parameters

      • length: number

        The number of random bytes to generate

      Returns Uint8Array

      Array containing the random bytes