tourze/tls-key-format
最新稳定版本:0.0.1
Composer 安装命令:
composer require tourze/tls-key-format
包简介
TLS密钥格式处理工具,支持PEM/DER格式转换
README 文档
README
A PHP library for handling TLS key format conversions between PEM and DER formats.
Features
- Convert between PEM and DER formats
- Validate PEM and DER format data
- Extract key and certificate information from PEM files
- Handle certificates and private keys
- Comprehensive error handling with exceptions
Installation
composer require tourze/tls-key-format
Usage
Basic Usage
<?php use Tourze\TLSKeyFormat\PemDerFormat; use Tourze\TLSKeyFormat\KeyHandler; use Tourze\TLSKeyFormat\CertificateHandler; // Initialize the format handler $formatter = new PemDerFormat(); // Convert PEM to DER $pemData = file_get_contents('certificate.pem'); $derData = $formatter->pemToDer($pemData); // Convert DER to PEM $pemData = $formatter->derToPem($derData, 'CERTIFICATE'); // Validate formats if ($formatter->isValidPem($pemData)) { echo "Valid PEM format\n"; } if ($formatter->isValidDer($derData)) { echo "Valid DER format\n"; } // Extract information from PEM $info = $formatter->extractFromPem($pemData); echo "Type: " . $info['type'] . "\n";
Key Handling
<?php use Tourze\TLSKeyFormat\KeyHandler; $keyHandler = new KeyHandler(); // Generate a new key pair $keyPair = $keyHandler->generateKeyPair(); // Work with keys $privateKey = $keyPair['private']; $publicKey = $keyPair['public'];
Certificate Handling
<?php use Tourze\TLSKeyFormat\CertificateHandler; $certHandler = new CertificateHandler(); // Parse certificate $certInfo = $certHandler->parseCertificate($pemData); // Validate certificate if ($certHandler->validateCertificate($pemData)) { echo "Certificate is valid\n"; }
Configuration
No configuration is required. The library works out of the box with default settings.
Examples
Complete Example
<?php require_once 'vendor/autoload.php'; use Tourze\TLSKeyFormat\PemDerFormat; use Tourze\TLSKeyFormat\Exception\KeyFormatException; try { $formatter = new PemDerFormat(); // Load a PEM certificate $pemData = file_get_contents('example.pem'); // Convert to DER $derData = $formatter->pemToDer($pemData); // Convert back to PEM $pemResult = $formatter->derToPem($derData, 'CERTIFICATE'); // Extract information $info = $formatter->extractFromPem($pemData); echo "Certificate type: " . $info['type'] . "\n"; echo "Data length: " . strlen($info['data']) . " bytes\n"; } catch (KeyFormatException $e) { echo "Error: " . $e->getMessage() . "\n"; }
References
License
This project is licensed under the MIT License - see the LICENSE file for details.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-05-25