承接 horsev/expiring-key-generator 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

horsev/expiring-key-generator

最新稳定版本:v1.0.0

Composer 安装命令:

composer require horsev/expiring-key-generator

包简介

Generate date-based expiring keys with SHA256 hashing and time-window validation

README 文档

README

Generate date-based keys and validate them within a time window. Uses a secret alphabet for base-N encoding + SHA256 hashing.

PHP port of expiring-key-generator — keys are cross-compatible with the same secret.

  • Zero dependencies (besides PHP 8.1+)
  • Algorithmic generation
  • No database needed

Install

composer require horsev/expiring-key-generator

Usage

<?php

use Horsev\ExpiringKeyGenerator\ExpiringKeyGenerator;

// 1. Generate a secret key (store this securely)
$secretKey = ExpiringKeyGenerator::generateSecretKey();

// 2. Daily keys — generate and validate within N days
$generateKey = ExpiringKeyGenerator::createKeyGenerator($secretKey);
$key = $generateKey(new DateTime());
$isKeyValid = ExpiringKeyGenerator::createKeyValidator($secretKey);
$isKeyValid($key, new DateTime(), 28); // true

// 3. Hourly keys — generate and validate within N hours (1–24)
$generateHourlyKey = ExpiringKeyGenerator::createHourlyKeyGenerator($secretKey);
$hourlyKey = $generateHourlyKey(new DateTime());
$isHourlyKeyValid = ExpiringKeyGenerator::createHourlyKeyValidator($secretKey);
$isHourlyKeyValid($hourlyKey, new DateTime(), 5); // true

API

generateSecretKey(): string

Returns a randomly shuffled 34-character string from a safe alphabet (A-Z without O, 1-9 without 0).

createKeyGenerator(string $secretKey): Closure

Throws if $secretKey is not a valid 34-character permutation of the safe alphabet.

Returns fn(DateTimeInterface $date): string that encodes a date into a deterministic base64 SHA256 hash.

createKeyValidator(string $secretKey): Closure

Throws if $secretKey is invalid.

Returns fn(string $hash, DateTimeInterface $currentDate, int $days): bool that checks whether a key was generated within the last $days days.

createHourlyKeyGenerator(string $secretKey): Closure

Returns fn(DateTimeInterface $date): string that encodes date+hour into a hash. Uses YYYYMMDDHH (10 digits).

createHourlyKeyValidator(string $secretKey): Closure

Returns fn(string $hash, DateTimeInterface $currentDate, int $hours): bool for 1–24 hour windows.

License

MIT

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固