Encrypted Pouch - v0.1.0
    Preparing search index...

    Class EncryptionHelper

    Helper class for encrypting and decrypting data using AES-256-GCM.

    Features:

    • AES-256-GCM authenticated encryption
    • Random IV for each encryption (prevents pattern analysis)
    • PBKDF2 key derivation (100k iterations by default)
    • Key caching for performance
    const helper = new EncryptionHelper('my-password');
    const encrypted = await helper.encrypt('secret data');
    const decrypted = await helper.decrypt(encrypted);
    Index

    Constructors

    Methods

    Constructors

    • Creates a new EncryptionHelper instance.

      Parameters

      • passphrase: string

        Password or key material for encryption

      • Optionalcrypto: CryptoInterface

        Optional custom crypto implementation (defaults to WebCrypto API)

      • passphraseMode: "derive" | "raw" = "derive"

        Key derivation mode:

        • "derive" (default): Use PBKDF2 with 100k iterations for user passphrases
        • "raw": Use SHA-256 only, for pre-derived keys or advanced use cases

      Returns EncryptionHelper

    Methods

    • Encrypts a string using AES-256-GCM.

      Each encryption uses a unique random IV (Initialization Vector), so encrypting the same data twice produces different ciphertext.

      Parameters

      • data: string

        Plaintext string to encrypt

      Returns Promise<string>

      Encrypted data as hex string in format: "iv|ciphertext"

      const helper = new EncryptionHelper('password');
      const encrypted = await helper.encrypt('secret data');
      // Returns something like: "a1b2c3d4e5f6g7h8i9j0k1l2|m3n4o5p6q7r8s9t0..."
    • Decrypts a string that was encrypted with the encrypt() method.

      Parameters

      • data: string

        Encrypted data in "iv|ciphertext" hex format

      Returns Promise<string>

      Decrypted plaintext string

      If decryption fails (wrong password, corrupted data, etc.)

      const helper = new EncryptionHelper('password');
      try {
      const decrypted = await helper.decrypt(encrypted);
      console.log('Decrypted:', decrypted);
      } catch (error) {
      if (error instanceof DecryptionError) {
      console.error('Wrong password or corrupted data');
      }
      }