bentools/shh
Shh! is a lightweight PHP library for handling secrets: generate RSA key pairs, change private key passphrases, encrypt/decrypt payloads, and store encrypted secrets safely so only holders of the private key can decrypt.
.env files, database secrets, or API keys). It’s particularly useful for:
config, cache, or filesystem for secure storage.Encrypter (which uses AES) by adding asymmetric encryption (RSA) for key exchange or hybrid encryption schemes.Vault (if using Laravel 10+) or custom secret managers.Hash facade for passphrase-based key derivation.openssl_* calls with Shh for consistency.Shh, then store in Laravel’s cache or database).Encrypter to support RSA-wrapped keys (advanced).Vault, AWS KMS, or encrypted filesystem). Loss of private keys = irreversible data loss.filesystem with strict permissions or integrate with a secrets manager (e.g., HashiCorp Vault).cache facade) and use shorter keys (e.g., 2048-bit) where possible.openssl_encrypt with OPENSSL_RAW_DATA flag).storage/, AWS Secrets Manager, etc.)Shh and Laravel’s Encrypter) during migration?Encrypter (AES-256-CBC) with Shh for asymmetric use cases.storage/app/secrets/ (with filesystem disk).database connection to store encrypted blobs (e.g., encrypted_secrets table).cache:remember() or Redis.Shh keys to Laravel’s config (e.g., config/shh.php).ramsey/uuid (if generating UUID-based key IDs).spatie/laravel-encryption (for hybrid encryption patterns).Phase 1: Proof of Concept (PoC)
Encrypter (benchmark with microtime()).storage/).Phase 2: Hybrid Integration
Encrypter to support RSA-wrapped keys:
// app/Services/HybridEncrypter.php
use BenTools\Shh\Shh;
use Illuminate\Contracts\Encryption\Encrypter as LaravelEncrypter;
class HybridEncrypter implements LaravelEncrypter {
public function encrypt($value, $key = null): string {
$rsaKey = Shh::encrypt($value, $publicKey);
return LaravelEncrypter::encrypt($rsaKey);
}
}
Phase 3: Full Adoption
Shh-encrypted storage.openssl_* usage in the codebase.OPENSSL_RAW_DATA and OPENSSL_PKCS1_OAEP_PADDING are supported.Shh).shh:generate Artisan command to output keys to storage/shh/.// app/Console/Commands/GenerateShhKeys.php
use BenTools\Shh\Shh;
use Illuminate\Console\Command;
class GenerateShhKeys extends Command {
public function handle() {
[$publicKey, $privateKey] = Shh::generateKeyPair(
env('SHH_PASSPHRASE'),
['private_key_bits' => 2048]
);
file_put_contents(storage_path('shh/public.key'), $publicKey);
file_put_contents(storage_path('shh/private.key'), $privateKey);
}
}
openssl_encrypt() calls with Shh::encrypt().$encrypted = Shh::encrypt('sensitive-data', file_get_contents(storage_path('shh/public.key')));
Shh::decrypt() with the private key (loaded securely).$decrypted = Shh::decrypt($encrypted, file_get_contents(storage_path('shh/private.key')));
scheduler to backup keys to a secure location weekly.Shh usage (e.g., which secrets are accessed/decrypted).openssl rsa -check..env.Shh::getError() to catch OpenSSL errors.Shh failures (e.g., ShhDecryptionFailedException).How can I help you explore Laravel packages today?