承接 web-auth/cose-lib 相关项目开发

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

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

web-auth/cose-lib

Composer 安装命令:

composer require web-auth/cose-lib

包简介

CBOR Object Signing and Encryption (COSE) For PHP

关键字:

README 文档

README

CI Latest Stable Version Total Downloads License

CBOR Object Signing and Encryption (COSE) for PHP is a comprehensive library that provides full support for COSE operations including signing, encryption, and MAC (Message Authentication Code) operations.

This library implements:

Features

Complete COSE Tag Support

  • COSE_Sign1 (tag 18) - Single signature
  • COSE_Sign (tag 98) - Multiple signatures
  • COSE_Encrypt0 (tag 16) - Single recipient encryption
  • COSE_Encrypt (tag 96) - Multiple recipients encryption
  • COSE_Mac0 (tag 17) - MAC without recipients
  • COSE_Mac (tag 97) - MAC with recipients

Cryptographic Algorithms

  • Signatures: ECDSA (ES256, ES384, ES512, ES256K), EdDSA (Ed25519, Ed448), RSA (RS256/384/512, PS256/384/512)
  • MAC: HMAC with SHA-256/384/512
  • Compatible with WebAuthn, FIDO2, and digital COVID certificates

Modern PHP

  • PHP 8.1+ with strict types
  • Full type safety and PHPStan compliance
  • Comprehensive test coverage

Installation

Install the library with Composer:

composer require web-auth/cose-lib

For COSE tag support (Sign, Encrypt, Mac operations), also install:

composer require spomky-labs/cbor-php

Quick Start

Verifying a COSE_Sign1 Signature

use CBOR\Decoder;
use CBOR\OtherObject\OtherObjectManager;
use CBOR\StringStream;
use CBOR\Tag\TagManager;
use Cose\Signature\CoseSign1Tag;
use Cose\Signature\Signature1;

// Setup decoder with COSE tag support
$tagManager = TagManager::create()->add(CoseSign1Tag::class);
$decoder = Decoder::create($tagManager, OtherObjectManager::create());

// Decode COSE_Sign1 message
$stream = new StringStream($encodedData);
$coseSign1 = $decoder->decode($stream);

// Extract components
$protectedHeader = $coseSign1->getProtectedHeader();
$payload = $coseSign1->getPayload();
$signature = $coseSign1->getSignature();

// Create signature structure for verification
$sigStructure = Signature1::create($protectedHeader, $payload);

// Verify (example with OpenSSL)
$isValid = openssl_verify(
    (string) $sigStructure,
    $derSignature,
    $publicKey,
    'sha256'
);

Creating a COSE_Sign1 Message

use CBOR\ByteStringObject;
use CBOR\MapItem;
use CBOR\MapObject;
use CBOR\NegativeIntegerObject;
use CBOR\UnsignedIntegerObject;
use Cose\Signature\CoseSign1Tag;

// Define headers
$protectedHeader = MapObject::create([
    MapItem::create(
        UnsignedIntegerObject::create(1), // alg
        NegativeIntegerObject::create(-7) // ES256
    ),
]);

$unprotectedHeader = MapObject::create([
    MapItem::create(
        UnsignedIntegerObject::create(4), // kid
        ByteStringObject::create('my-key-id')
    ),
]);

// Create COSE_Sign1
$coseSign1 = CoseSign1Tag::create(
    $protectedHeader,
    $unprotectedHeader,
    ByteStringObject::create('Message to sign'),
    ByteStringObject::create($signatureBytes)
);

// Encode to CBOR
$encoded = (string) $coseSign1;

Documentation

Use Cases

This library is perfect for:

  • 🏥 Digital Health Certificates - COVID-19 vaccination passes (EU Digital COVID Certificate)
  • 🔐 WebAuthn/FIDO2 - Authenticator attestation and assertion signatures
  • 📱 IoT Security - Secure messaging for constrained devices
  • 🌐 Web PKI - CBOR-based certificate chains
  • 📄 Document Signing - Compact digital signatures

Supported Algorithms

Signature Algorithms

Algorithm Identifier Description
ES256 -7 ECDSA with SHA-256
ES384 -35 ECDSA with SHA-384
ES512 -36 ECDSA with SHA-512
ES256K -47 ECDSA with secp256k1
EdDSA -8 EdDSA
Ed25519 - EdDSA with Curve25519
RS256 -257 RSASSA-PKCS1-v1_5 with SHA-256
RS384 -258 RSASSA-PKCS1-v1_5 with SHA-384
RS512 -259 RSASSA-PKCS1-v1_5 with SHA-512
PS256 -37 RSASSA-PSS with SHA-256
PS384 -38 RSASSA-PSS with SHA-384
PS512 -39 RSASSA-PSS with SHA-512

MAC Algorithms

Algorithm Identifier Description
HS256 5 HMAC with SHA-256
HS384 6 HMAC with SHA-384
HS512 7 HMAC with SHA-512
HS256/64 4 HMAC with SHA-256 truncated to 64 bits

Testing

Run the test suite with:

composer test

Or using Castor:

castor phpunit

The library includes comprehensive tests including:

  • Unit tests for all COSE tag types
  • Integration tests with real cryptographic operations
  • COVID-19 certificate verification examples
  • Test fixtures with actual certificates

Requirements

  • PHP 8.1 or higher
  • ext-json
  • ext-openssl
  • brick/math
  • spomky-labs/pki-framework
  • spomky-labs/cbor-php (for COSE tag support)

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for details.

For security vulnerabilities, please email security [at] spomky-labs.com instead of using the issue tracker.

Support

I bring solutions to your problems and answer your questions.

If you really love this project and the work I have done, or if you want me to prioritize your issues, you can support me:

License

This software is released under the MIT License.

Credits

Maintained by Florent Morselli and contributors.

Made with ❤️ for the PHP community

web-auth/cose-lib 适用场景与选型建议

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

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

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

围绕 web-auth/cose-lib 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

与 web-auth/cose-lib 相关的其它包

同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:

统计信息

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

GitHub 信息

  • Stars: 18
  • Watchers: 1
  • Forks: 10
  • 开发语言: PHP

其他信息

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