UNPKG

fallout-utility

Version:
40 lines (39 loc) 1.32 kB
/// <reference types="node" /> /// <reference types="node" /> import { CipherGCMTypes } from 'node:crypto'; export interface EncryptionOptions { secret: string; ivLength?: number; saltLength?: number; pbkdf2Iterations?: number; algorithm?: CipherGCMTypes; encoding?: BufferEncoding; } export interface EncryptionData extends Required<Omit<EncryptionOptions, 'tagLength' | 'ivLength' | 'saltLength'>> { encrypted: string; decrypted: string; iv: string; salt: string; tag: string; } export declare class Encryption { algorithm: CipherGCMTypes; secret: string; encoding: BufferEncoding; ivLength: number; saltLength: number; pbkdf2Iterations: number; readonly iv: Buffer; readonly salt: Buffer; constructor(options?: EncryptionOptions); saltSecret(options?: Pick<EncryptionData, 'pbkdf2Iterations'> & { salt?: Buffer; }): Buffer; encrypt(value: string): EncryptionData; decrypt(options: Omit<Partial<EncryptionData>, 'decrypted' | 'encrypted' | 'secret' | 'tag'> & { encrypted: string; tag: string; }): EncryptionData; static encrypt(value: string, secret: string, encoding?: BufferEncoding): string; static decrypt(encrypted: string, secret: string, encoding?: BufferEncoding): string; }