Download the PHP package hejunjie/encrypted-request without Composer

On this page you can find all versions of the php package hejunjie/encrypted-request. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package encrypted-request

hejunjie/encrypted-request

English | 简体中文

A PHP encryption toolkit for secure front-end to back-end communication.

In real-world development, API endpoints often require security: data needs encryption to prevent sniffing, and requests must be protected from tampering and replay attacks. Coordinating encryption methods and signature rules with the front-end can be tedious. This package, paired with the front-end npm package, lets the front-end generate encrypted request parameters with a single call, while the back-end decrypts and verifies in just a few lines of code.

Front-end companion npm package: npm-encrypted-request

This project has been parsed by Zread. Click to learn more: Learn More

Features

Installation

Quick Start

1. Configuration

Via .env file:

Or via an array:

2. Decrypt Requests

[!WARNING] Without the third argument, the default InMemoryNonceValidator stores nonces in process memory, which is lost after each PHP request — it cannot truly prevent replay attacks. Always pass a custom Nonce validator in production. See the "Custom Nonce Validator" section below.

Configuration Reference

Config Type Required Default Description
RSA_PRIVATE_KEY string ✅ - RSA private key for decrypting the AES key from the front-end
SIGN_SECRET string ✅ - HMAC-SHA256 signing key, must match the front-end
DEFAULT_TIMESTAMP_DIFF int ❌ 60 Timestamp tolerance in seconds
NONCE_TTL int ❌ 300 Nonce time-to-live in seconds

How It Works

  1. Signature verification (runs first): HMAC-SHA256 over en_data + enc_payload + timestamp using SIGN_SECRET. Invalid requests are rejected immediately.
  2. Timestamp check: Ensures the request timestamp is within the configured tolerance.
  3. RSA decryption: Decrypts enc_payload with the RSA private key to obtain the AES key, IV, and Nonce.
  4. Nonce verification: Checks whether the Nonce has been used before, preventing replay attacks.
  5. AES-256-GCM decryption: Decrypts the request data using the extracted AES key and IV.

Front-End Integration

The front-end uses the hejunjie-encrypted-request npm package to generate encrypted data:

The PHP back-end can then decrypt directly using EncryptedRequestHandler.

Custom Nonce Validator

The default InMemoryNonceValidator stores nonces in process memory and is only suitable for single-process or testing environments. For production, implement the NonceValidatorInterface (e.g., with Redis, APCu, or a database) and pass it as the third argument to the EncryptedRequestHandler constructor:

Directory Structure

Compatibility

FAQ

Is the default Nonce validator suitable for production?

No. InMemoryNonceValidator stores data in process memory, which is lost after each PHP request — it cannot reliably prevent replay attacks. For production, inject a Redis or database-backed implementation as shown in the "Custom Nonce Validator" section above.

How do I keep the signing key consistent between front-end and back-end?

The SIGN_SECRET value must exactly match the signSecret parameter passed to encryptRequest() on the front-end. Store the key in .env and sync it to the front-end through a secure channel.

Which PHP frameworks are supported?

Any project following PSR-4 autoloading, including but not limited to Laravel, Symfony, Slim, ThinkPHP, and plain PHP projects.

Contributing

Issues and pull requests are welcome.


All versions of encrypted-request with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
vlucas/phpdotenv Version ^5.6
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package hejunjie/encrypted-request contains the following files

Loading the files please wait ...