php-standard-library/hash
Hash utilities for PHP: cryptographic and non-cryptographic hashing via an Algorithm enum, HMAC helpers, and timing-safe string comparison. Lightweight package from PHP Standard Library for consistent, secure hashing across projects.
Hash facade for passwords). Its algorithm-agnostic approach supports both cryptographic (SHA-256, BCRYPT) and non-cryptographic (MD5, CRC32) use cases, making it versatile for checksums, cache keys, or API signatures.hash() calls or custom hashing logic. For example:
// Before
$checksum = hash('sha256', $data);
// After
$checksum = HashGenerator::generate($data, Algorithm::SHA256);
app('hash')->generate()), creating a seamless bridge between the package and Laravel’s Hash facade.Hash facade (e.g., reserve this package for non-password hashing only). This prevents confusion and ensures maintainability.Hash facade. Mitigate by documenting a strict boundary (e.g., "Use php-standard-library/hash exclusively for non-password data").hash()) or Symfony’s SecurityComponent if the package stagnates.hash() for high-throughput scenarios (e.g., bulk file checksums or distributed systems).HashComparator is used correctly in all sensitive comparisons (e.g., tokens, API keys). Incorrect usage could expose timing vulnerabilities.Hash facade, or is it exclusively for non-password hashing? Document this explicitly in team guidelines.ext-sodium or paragonie/hmac.hash() for critical paths (e.g., 10K+ operations/sec). Use tools like Blackfire or Xdebug to identify bottlenecks.HashComparator and edge cases (e.g., empty strings, binary data).hash() or Symfony’s SecurityComponent). Use feature flags for gradual adoption.ext-hash, ext-sodium) or Laravel’s Hash facade.Hash facade (for passwords).SecurityComponent (if using its hashing utilities).hash(), password_hash()).composer require php-standard-library/hash
hash() calls to ensure consistency.md5(), sha1(), or hash()) with the package’s API.// Before (insecure)
$checksum = md5(file_get_contents($file));
// After (standardized)
$checksum = HashGenerator::generate(file_get_contents($file), Algorithm::MD5);
// Before (custom HMAC)
$hmac = hash_hmac('sha256', $data, $key);
// After (standardized)
$hmac = HMAC::generate($data, $key, Algorithm::SHA256);
// app/Providers/HashServiceProvider.php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use PhpStandardLibrary\Hash\HashGenerator;
use PhpStandardLibrary\Hash\Algorithm;
class HashServiceProvider extends ServiceProvider
{
public function register()
{
$this->app->singleton('hash', function () {
return new HashGenerator();
});
}
}
public function __construct(private HashGenerator $hash) {}
// app/Facades/Hash.php
namespace App\Facades;
use Illuminate\Support\Facades\Facade;
class Hash extends Facade
{
protected static function getFacadeAccessor() { return 'hash'; }
}
$checksum = Hash::generate($data, Algorithm::SHA256);
ext-sodium or paragonie/hmac.hash('sha256', 'data')).file_get_contents()).null, large payloads).Hash facade—keep passwords separate to prevent scope creep.composer.json and run composer update.HashComparator).config('hash.use_standard_library')) for gradual adoption:
// config/hash.php
'use_standard_library' => env('HASH_USE_STANDARD_LIBRARY', false),
md5(), sha1()).hash() or Symfony’s SecurityComponent.How can I help you explore Laravel packages today?