Encryption
Introduction
H3ravel provides a simple and convenient API for encrypting and decrypting data using OpenSSL. It supports both AES-256 and AES-128 encryption algorithms and automatically signs all encrypted values with a message authentication code (MAC) to prevent tampering or modification after encryption.
Configuration
Before using the encrypter, ensure that an encryption key is defined in your src/config/app.ts configuration file. This key is managed by the APP_KEY environment variable.
You can generate a secure application key using the Musket command:
sh
$ npm musket key:generatesh
$ yarn musket key:generatesh
$ pnpm musket key:generatesh
$ bun musket key:generateThis command uses Node's built-in crypto.randomBytes function to create a cryptographically secure key. In most cases, this key will be automatically generated during H3ravel’s installation.