UNPKG

ashcrypt

Version:
65 lines (61 loc) 2.12 kB
// Generated by dts-bundle-generator v9.5.1 import { CipherGCMTypes } from 'crypto'; import { WriteStream } from 'fs'; import { Transform } from 'stream'; export declare abstract class BaseAlgorithm { readonly name: string; readonly chunkSize: number; constructor({ name, chunkSize }: AlgorithmOptions); abstract getChunkSize(baseChunkSize: number): number; abstract encrypt(buffer: Buffer<ArrayBufferLike>): Promise<Buffer<ArrayBuffer>>; abstract decrypt(cipher: Buffer<ArrayBufferLike>): Promise<Buffer<ArrayBuffer>>; } export declare class AES extends BaseAlgorithm { readonly IV_LENGTH: number; readonly TAG_LENGTH: number; readonly SALT_LENGTH: number; readonly TAG_POSITION: number; readonly ENCRYPTED_POSITION: number; readonly KEYLEN: number; readonly HASH: string; readonly algorithm: CipherGCMTypes; private readonly secret; readonly iterations: number; constructor({ secret, chunkSize, algorithm, iterations }: AESOptions); getKey(salt: Buffer): Promise<Buffer<ArrayBufferLike> | Error>; getChunkSize(baseChunkSize: number): number; encrypt(buffer: Buffer<ArrayBufferLike>): Promise<Buffer<ArrayBuffer>>; decrypt(cipher: Buffer<ArrayBufferLike>): Promise<Buffer<ArrayBuffer>>; } export declare class Stream<Algorithm extends BaseAlgorithm> { readonly algorithm: Algorithm; readonly parallel: number; constructor({ algorithm, maxParallel }: StreamOptions<Algorithm>); /** * Creates a Transform stream for encryption/decryption with proper chunk sizes */ create(type: "decrypt" | "encrypt"): Transform; /** * Reads an encrypted file and returns a decrypted stream */ read(path: string, type: "decrypt" | "encrypt"): Transform; /** * Returns a Transform stream that encrypts data and writes to the specified path */ write(path: string): WriteStream; } export type AESOptions = { secret: string; chunkSize?: number; algorithm?: CipherGCMTypes; iterations?: number; }; export type AlgorithmOptions = { name: string; chunkSize: number; }; export type StreamOptions<Algorithm extends BaseAlgorithm> = { algorithm: Algorithm; maxParallel?: number; }; export {};