northrook/hasher 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

northrook/hasher

Composer 安装命令:

composer require northrook/hasher

包简介

Crockford Base32 hashing utilities for short, URL-safe identifiers, checksums, and time-sortable prefixes

README 文档

README

Crockford Base32 hashing utilities for short, URL-safe identifiers, checksums, and time-sortable prefixes.

Requires PHP 8.4+. No runtime Composer dependencies.

Requirements

  • PHP >=8.4
  • ext-hash (xxHash32 via hash('xxh32', …))
  • ext-random (Random\Randomizer for crypto())

Installation

composer require northrook/hasher

Quick start

use Northrook\Hash;

Hash::checksum('hello');                  // '03XG0XZS'
Hash::time(10, seed: 1_700_000_000_000);  // '01HF7YAT00'
Hash::crypto();                           // 16-char CSPRNG token

API reference

MethodDefault lengthRangePurpose
xxh32(string $value)n/an/aRaw 8-char lowercase hex digest
checksum(string $value)8 (fixed)n/aCanonical Crockford Base32 checksum
value(string $value, int $length = 8)84–8Truncated Crockford Base32 digest (LSB end)
time(int $length = 10, null\|int\|float $seed = null)101–16Millisecond timestamp as sortable Base32
fast(int $length = 8)81–32Fast random (mt_rand); not for secrets
crypto(int $length = 16)168–32CSPRNG random (Random\Randomizer)

time() seed: null → current time (ms); int → milliseconds since epoch; float → seconds (fractional part included). Length 10 gives full millisecond sortability.

Examples

Checksums and digests

Hash::xxh32('hello');      // 'fb0077f9'
Hash::checksum('hello');   // '03XG0XZS'
Hash::value('hello', 4);   // '0XZS'
Hash::checksum('café');    // '00ZXTEE1'

Time-sortable prefixes

Hash::time(10, seed: 1_700_000_000_000); // '01HF7YAT00'
Hash::time(8, seed: 1_700_000_000_000);  // 'HF7YAT00' — suffix of the 10-char form

Random tokens

Hash::fast(8);    // non-cryptographic — UI keys, low-stakes nonces
Hash::crypto(16); // secrets, session tokens, API keys

Composite IDs

$id = Hash::time(10) . Hash::crypto(16);

checksum(), value(), xxh32(), and fast() are not for security-sensitive use.

Use crypto() for secrets and unguessable tokens.

Development

composer test
composer phpstan

License

BSD-3-Clause. See LICENSE.

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2026-07-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固