Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Zend Crypt Laravel Package

zendframework/zend-crypt

Zend\Crypt provides secure PHP cryptography utilities including encryption/decryption, hashing, HMAC, key generation, and password adapters. Designed for Zend Framework apps but usable standalone, with pluggable algorithms and safer defaults for common crypto tasks.

View on GitHub
Deep Wiki
Context7

Getting Started

Start by installing the package via Composer (though note it’s archived and unmaintained—see Gotchas). For new projects, consider migrating to paragonie/whirlpool, defuse/php-encryption, or Laravel’s native Hash/Crypt facades. If constrained to use zend-crypt (e.g., legacy code), install with:

composer require zendframework/zend-crypt

First use case: securely hashing passwords using Bcrypt:

use Zend\Crypt\Password\Bcrypt;

$bcrypt = new Bcrypt(['cost' => 12]);
$hashed = $bcrypt->create('user_password');
$valid   = $bcrypt->verify('user_password', $hashed);

Check src/Password/ and src/Symmetric/ in the repo for core classes—start with PasswordFactory or BlockCipher for basic workflows.

Implementation Patterns

  • Password hashing: Always use Zend\Crypt\Password\Bcrypt (or Scrypt/Pbkdf2 if required). Avoid rolling custom hashers—validate against stored hashes via verify() with constant-time comparison.
  • Symmetric encryption: Use BlockCipher with modern algorithms (e.g., AES-256-CBC). Generate keys with Zend\Crypt\Key\Derivation\PBKDF2 (never hardcode secrets):
    use Zend\Crypt\BlockCipher;
    use Zend\Crypt\Key\Derivation\PBKDF2;
    
    $cipher = BlockCipher::factory('openssl', ['algo' => 'aes-256-cbc']);
    $key = PBKDF2::derive('master_secret', 'salt123', 100000, 32);
    $cipher->setKey($key);
    
    $encrypted = $cipher->encrypt(['data' => 'sensitive_value']);
    $decrypted = $cipher->decrypt($encrypted);
    
  • Randomness & HMAC: Use Zend\Crypt\Random for tokens (e.g., CSRF):
    $token = bin2hex(Random::getString(32)); // or ->getRandomBytes(32)
    
    For integrity:
    use Zend\Crypt\Hash;
    $hash = Hash::compute('sha256', 'secret_key', $message);
    

Integrate into Laravel via a custom Encrypter wrapper or store sensitive config values encrypted in .env (derive key per-environment).

Gotchas and Tips

⚠️ Critical: This package is archived (since 2019) and unmaintained. Prefer Laravel’s built-in Crypt (which uses OpenSSL directly) or modern standalone libraries like defuse/php-encryption. Using zend-crypt in new code introduces unpatched security risks.

  • Algorithm defaults: BlockCipher defaults to openssl and mcrypt—but mcrypt is removed in PHP 7.2+. Ensure openssl is used explicitly.
  • IV handling: BlockCipher manages IVs automatically (appends to ciphertext), but ensure storage/transmission preserves the full payload. Never reuse keys across environments without re-derivation.
  • Password verification timing: Always use verify()not ===—to prevent timing attacks.
  • Configuration quirks: The Zend\Crypt\Password\PasswordAdapterFactory requires strict config format (['algorithm' => 'bcrypt', 'cost' => 13]). Misformatted configs silently fallback or throw.
  • Extensibility: Extend Zend\Crypt\Password\PasswordInterface for custom schemes (e.g., Argon2 via password_hash() wrapper), but validate thoroughly.
  • Debugging tip: Enable zend-crypt’s internal exception logging by wrapping operations in try/catch—errors like invalid IVs or bad keys throw Exception\RuntimeException.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport