highperapp/crypto
Composer 安装命令:
composer require highperapp/crypto
包简介
Enterprise-grade cryptographic library with OWASP A02 compliance, FIPS 140-2 support, and advanced security features
关键字:
README 文档
README
High-performance cryptographic utilities and secure operations that work with any PHP project.
🔄 Standalone Library: This package works independently and can be used in any PHP application - no HighPer framework required!
Features
- 🔐 Modern Encryption: Libsodium-based encryption with ChaCha20-Poly1305
- 🔑 Key Management: Secure key generation, derivation, and storage
- 📝 Multi-Token Support: JWT, PASETO, and OAuth 2.0 token handling
- 🛡️ Password Hashing: Argon2id password hashing with configurable parameters
- 🔒 Digital Signatures: Ed25519 digital signatures for data integrity
- ⚡ Async Operations: Non-blocking cryptographic operations with AMPHP
- 🎯 Secure Random: Cryptographically secure random number generation
- 🔧 Environment-Driven: Configure token providers via environment variables
Installation
composer require highperapp/crypto
Quick Start
Encryption/Decryption
<?php use HighPerApp\HighPer\Crypto\SymmetricEncryption; $crypto = new SymmetricEncryption(); // Generate a key $key = $crypto->generateKey(); // Encrypt data $encrypted = yield $crypto->encrypt('sensitive data', $key); // Decrypt data $decrypted = yield $crypto->decrypt($encrypted, $key);
Token Authentication (JWT/PASETO/OAuth)
<?php use HighPerApp\HighPer\Crypto\Auth\TokenAuthManager; // Environment-driven token provider selection $tokenAuth = new TokenAuthManager(); // Create token $token = yield $tokenAuth->createToken(['user_id' => 123, 'role' => 'admin']); // Verify token $payload = yield $tokenAuth->verifyToken($token); // Get token information $info = yield $tokenAuth->getTokenInfo($token);
JWT Provider
<?php // Set environment variables or pass config $config = [ 'provider' => 'jwt', 'jwt' => [ 'secret' => 'your-jwt-secret', 'algorithm' => 'HS256', 'issuer' => 'your-app', 'audience' => 'your-users' ] ]; $tokenAuth = new TokenAuthManager($config);
PASETO Provider (More Secure)
<?php // Environment variables or config $config = [ 'provider' => 'paseto', 'paseto' => [ 'version' => 'v4', 'purpose' => 'local', // or 'public' 'key' => 'your-32-byte-key', 'issuer' => 'your-app' ] ]; $tokenAuth = new TokenAuthManager($config);
OAuth 2.0 Provider
<?php $config = [ 'provider' => 'oauth', 'oauth' => [ 'client_id' => 'your-client-id', 'client_secret' => 'your-client-secret', 'authorization_endpoint' => 'https://auth.example.com/oauth/authorize', 'token_endpoint' => 'https://auth.example.com/oauth/token', 'redirect_uri' => 'https://yourapp.com/callback' ] ]; $tokenAuth = new TokenAuthManager($config); // Get authorization URL $authUrl = $tokenAuth->getProvider()->getAuthorizationUrl(); // Exchange code for token $tokenData = yield $tokenAuth->getProvider()->exchangeCodeForToken($code);
Password Hashing
<?php use HighPerApp\HighPer\Crypto\PasswordHasher; $hasher = new PasswordHasher(); // Hash password $hash = yield $hasher->hash('user-password'); // Verify password $isValid = yield $hasher->verify('user-password', $hash);
Environment Configuration
Configure token providers via environment variables:
# General Token Settings HIGHPER_TOKEN_PROVIDER=jwt # jwt, paseto, or oauth HIGHPER_TOKEN_EXPIRES_IN=3600 # Default token expiration # JWT Configuration HIGHPER_JWT_ENABLED=true HIGHPER_JWT_SECRET=your-secret-key HIGHPER_JWT_ALGORITHM=HS256 HIGHPER_JWT_ISSUER=your-app HIGHPER_JWT_AUDIENCE=your-users HIGHPER_JWT_LEEWAY=60 # PASETO Configuration HIGHPER_PASETO_ENABLED=false HIGHPER_PASETO_VERSION=v4 HIGHPER_PASETO_PURPOSE=local # local or public HIGHPER_PASETO_KEY=your-32-byte-key HIGHPER_PASETO_ISSUER=your-app # OAuth Configuration HIGHPER_OAUTH_ENABLED=false HIGHPER_OAUTH_CLIENT_ID=your-client-id HIGHPER_OAUTH_CLIENT_SECRET=your-client-secret HIGHPER_OAUTH_REDIRECT_URI=https://yourapp.com/callback HIGHPER_OAUTH_AUTH_ENDPOINT=https://auth.provider.com/oauth/authorize HIGHPER_OAUTH_TOKEN_ENDPOINT=https://auth.provider.com/oauth/token HIGHPER_OAUTH_SCOPES=read,write HIGHPER_OAUTH_PKCE_ENABLED=true
Token Providers Comparison
| Feature | JWT | PASETO | OAuth |
|---|---|---|---|
| Security | Good | Excellent | Good |
| Standards | RFC 7519 | PASETO Spec | RFC 6749 |
| Stateless | ✅ | ✅ | ❌ |
| Refresh Support | ❌ | ❌ | ✅ |
| Revocation | ❌ | ❌ | ✅ |
| Complexity | Low | Low | High |
| Use Case | Simple auth | High security | Enterprise SSO |
Requirements
- PHP 8.2+
- ext-sodium
- ext-openssl
- AMPHP v3+
License
MIT
highperapp/crypto 适用场景与选型建议
highperapp/crypto 是一款 基于 Rust 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 10 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「security」 「oauth」 「Audit」 「encryption」 「hashing」 「async」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 highperapp/crypto 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 highperapp/crypto 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 highperapp/crypto 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Log adding/updating/deleting of elements
WeChat OAuth SDK
Doctrine ORM provider for the auditor audit-log library.
Ory-Hydra OAuth 2.0 Client Provider for The PHP League OAuth2-Client
Library for ORCID web services
A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 56
- 依赖项目数: 1
- 推荐数: 3
其他信息
- 授权协议: MIT
- 更新时间: 2025-10-03