Skip to content

EncryptionService derives key using SHA-256 hash instead of a proper KDF #800

Description

@RUKAYAT-CODER

Overview

src/security/encryption/encryption.service.ts derives its AES-256 key via crypto.createHash('sha256').update(secret).digest(). SHA-256 is a fast, unaided hash with no work factor, making brute-force key derivation trivial. A proper KDF (PBKDF2, scrypt, or Argon2) must be used instead.

Specifications

Features:

  • Derive the AES key using crypto.scryptSync (or Argon2) with a persistent, randomly-generated salt stored separately from the key material.

Tasks:

  • Replace createHash('sha256') with crypto.scryptSync(secret, salt, 32).
  • Store the salt in a separate env var (ENCRYPTION_SALT) and validate its presence at startup.
  • Document migration path for data encrypted with the old key.
  • Add unit tests that verify key derivation uses scrypt parameters.

Impacted Files:

  • src/security/encryption/encryption.service.ts
  • .env.example

Acceptance Criteria

  • Key derivation uses a KDF with configurable work factor.
  • Startup fails if ENCRYPTION_SECRET or ENCRYPTION_SALT are absent.
  • Existing encrypted data can be migrated with a one-time re-encryption script.

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions