定制 christian-riesen/base32 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

christian-riesen/base32

Composer 安装命令:

composer require christian-riesen/base32

包简介

Base32 encoder/decoder according to RFC 4648

README 文档

README

Base32 Encoder/Decoder for PHP according to RFC 4648.

CI

Latest Stable Version Total Downloads Latest Unstable Version License

Installation

Use composer:

composer require christian-riesen/base32

Usage

<?php

// Include class or user autoloader
use Base32\Base32;

$string = 'fooba';

// $encoded contains now 'MZXW6YTB'
$encoded = Base32::encode($string);

// $decoded is again 'fooba'
$decoded = Base32::decode($encoded);

You can also use the extended hex alphabet by using the Base32Hex class instead.

Strict decoding (2.0)

As of 2.0, decode() is strictly RFC 4648 conformant and rejects malformed input by throwing an \InvalidArgumentException, instead of silently stripping unknown characters as 1.x did. Decoding is case-sensitive and requires correct padding. It throws when the input is not uppercase, has a length that is not a multiple of 8, contains characters outside the alphabet or misplaced padding, or carries non-zero trailing bits (a non-canonical encoding).

encode() is unchanged and remains conformant, so anything produced by encode() still decodes cleanly. If you decode user-supplied strings (e.g. TOTP secrets that may be lowercase or spaced), normalize them first:

$secret = strtoupper(preg_replace('/\s+/', '', $userInput));
$bytes  = Base32::decode($secret);

See CHANGELOG.md for the full 2.0 migration notes.

About

Initially created to work with the one time password project, yet it can stand alone just as well as Jordi Boggiano kindly pointed out. It's the only Base32 implementation that passes the test vectors and contains unit tests as well.

Goal

Have a RFC compliant Base32 encoder and decoder. The implementation could be improved, but for now, it does the job and has unit tests. Ideally, the class can be enhanced while the unit tests keep passing.

Requirements

Works on PHP 8.1 and later (PHP 8.1, 8.2, 8.3 and 8.4 are tested in CI).

The 1.x releases support PHP 7.2 – 8.x; use those if you need to run on an older PHP version.

Tests run on PHPUnit 10.5.

Author

Christian Riesen chris.riesen@gmail.com https://christianriesen.com

Acknowledgements

Base32 is mostly based on the work of https://github.com/NTICompass/PHP-Base32

christian-riesen/base32 适用场景与选型建议

christian-riesen/base32 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 34.1M 次下载、GitHub Stars 达 133, 最近一次更新时间为 2013 年 01 月 29 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「encode」 「decode」 「base32」 「rfc4648」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 christian-riesen/base32 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 christian-riesen/base32 我们能提供哪些服务?
定制开发 / 二次开发

基于 christian-riesen/base32 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 133
  • Watchers: 6
  • Forks: 30
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-01-29