ferdhika31/php-crispy

A custom Crypto utility PHP library that ports and wraps cryptography concepts from the go-crypsi module to make life easier when working with Digest, Cipher, HMAC, RSA, and RSA Digital Signatures natively in PHP.

Maintainers

Package info

github.com/ferdhika31/php-crispy

pkg:composer/ferdhika31/php-crispy

Statistics

Installs: 7

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

0.0.1 2026-04-16 03:58 UTC

This package is auto-updated.

Last update: 2026-04-17 02:16:08 UTC


README

A custom Crypto utility PHP library that ports and wraps cryptography concepts from the go-crypsi module to make life easier when working with Digest, Cipher, HMAC, RSA, and RSA Digital Signatures natively in PHP.

Requirements

  • PHP 8.1 or higher
  • ext-openssl
  • ext-hash

Installation

You can install the package via composer:

composer require ferdhika31/php-crispy

(Note: During development, you can simply clone this repository and run composer install)

Features

The library is split into 4 core cryptography modules under the Ferdhika31\PhpCrispy namespace:

1. Aesx (Symmetric Encryption)

Provides AES encryption and decryption functions mapping to CBC, CFB, and GCM modes. It implicitly determines your AES key size (128, 192, or 256 bits).

use Ferdhika31\PhpCrispy\Aesx;

$key = "1234567890123456"; // 16 bytes = AES-128
$encrypted = Aesx::encryptCBC($key, "My Secret Data");
$decrypted = Aesx::decryptCBC($key, $encrypted);

2. Digestx (Hashing)

Provides easy-to-use variadic functions for standard checksums. Supports MD5, SHA1, SHA256, SHA384, and SHA512.

use Ferdhika31\PhpCrispy\Digestx;

$hex = Digestx::sha256Hex("hello", " ", "world"); 

3. Hmacx (Hash-based Message Authentication Code)

Provides HMAC signing capabilities guaranteeing data integrity, enforcing a minimum key length of 32 bytes for security.

use Ferdhika31\PhpCrispy\Hmacx;

$key = "super_secret_key_that_is_long_enough..";
$hmac = Hmacx::md5Hex($key, "My payload");

4. Rsax (Asymmetric Encryption & Signatures)

Provides RSA Key Generation, Public-Key Cryptography Standard (PKCS) Encryption via OAEP, and RSA Digital Signatures.

use Ferdhika31\PhpCrispy\Rsax;

// Generate pairs
$keys = Rsax::generateKeyPairs(2048);

// Sign Data
$signature = Rsax::signSha256($keys['private'], "Important Payload");

// Verify Data
$isValid = Rsax::verifySignSha256($keys['public'], "Important Payload", $signature);

Examples

To see full working examples for each algorithm, check the examples/ directory. Run them via terminal:

php examples/aes_sample.php
php examples/digest_sample.php
php examples/hmac_sample.php
php examples/rsa_sample.php

Testing

The library uses PHPUnit for robust testing. You can run the test suite by executing:

vendor/bin/phpunit tests

License

The MIT License (MIT). Please see License File for more information.