@me2em/crypto
    Preparing search index...

    Function encryptMediaChunk

    • Encrypts a single media chunk with a deterministic IV derived from the file key, recording ID, and chunk index.

      Uses direct WebCrypto crypto.subtle.encrypt with the deterministic nonce so that the decrypting side can recover the IV without storing it separately.

      Parameters

      • fileKeyRaw: Uint8Array

        The 32-byte per-file key.

      • chunk: Uint8Array

        The chunk data to encrypt.

      • recordingId: string

        Recording/file identifier for domain separation.

      • chunkIndex: number

        Sequential chunk index (0-based).

      Returns Promise<{ encrypted: Uint8Array; iv: Uint8Array }>

      Object with encrypted ciphertext (includes GCM tag) and IV.

      const { encrypted, iv } = await encryptMediaChunk(fileKey, chunkData, 'rec-42', 0);
      // store encrypted + iv; IV is recoverable via deriveChunkNonce