hawk-hhg/hawki-crypto 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

hawk-hhg/hawki-crypto

最新稳定版本:0.5.3

Composer 安装命令:

composer require hawk-hhg/hawki-crypto

包简介

The shared cryptographic module of HAWKI, providing secure encryption and decryption functionalities.

README 文档

README

A PHP library for cryptographic operations including symmetric, asymmetric, and hybrid encryption/decryption.

Installation

composer require hawk-hhg/hawki-crypto

Features

  • Symmetric Cryptography: Encrypt and decrypt data using a shared secret key
  • Asymmetric Cryptography: Public/private key encryption for secure communication
  • Hybrid Cryptography: Combines symmetric and asymmetric approaches for efficient secure communication

Usage

Symmetric Encryption

use Hawk\HawkiCrypto\SymmetricCrypto;

// Create instance
$crypto = new SymmetricCrypto();

// Encrypt data
$encrypted = $crypto->encrypt("sensitive data", "your-secret-key");

// Decrypt data
$decrypted = $crypto->decrypt($encrypted, "your-secret-key");

Asymmetric Encryption

use Hawk\HawkiCrypto\AsymmetricCrypto;
use Hawk\HawkiCrypto\Value\AsymmetricKeypair;

// Create instance
$crypto = new AsymmetricCrypto();

// Generate keypair
$keypair = $crypto->generateKeypair();

// Encrypt with public key
$encrypted = $crypto->encrypt("sensitive data", $keypair->getPublicKey());

// Decrypt with private key
$decrypted = $crypto->decrypt($encrypted, $keypair);

Hybrid Encryption

use Hawk\HawkiCrypto\HybridCrypto;
use Hawk\HawkiCrypto\SymmetricCrypto;
use Hawk\HawkiCrypto\AsymmetricCrypto;
use Hawk\HawkiCrypto\Value\AsymmetricKeypair;

// Create required instances
$hybridCrypto = new HybridCrypto(new SymmetricCrypto(), new AsymmetricCrypto());

// Generate keypair
$keypair = $asymmetricCrypto->generateKeypair();

// Encrypt with public key
$encrypted = $hybridCrypto->encrypt("sensitive data", $keypair->getPublicKey());

// Decrypt with private key
$decrypted = $hybridCrypto->decrypt($encrypted, $keypair);

Value Objects

The library provides several value objects for handling cryptographic operations:

  • AsymmetricKeypair: Represents a public/private key pair
  • AsymmetricPublicKey: Represents a public key
  • SymmetricCryptoValue: Encapsulates symmetrically encrypted data
  • HybridCryptoValue: Encapsulates hybrid encrypted data

All value objects can be serialized as JSON strings for easy storage and transmission like so:

use Hawk\HawkiCrypto\AsymmetricCrypto;

$crypto = new AsymmetricCrypto();

echo json_encode($crypto->generateKeypair()); // Outputs JSON representation of the keypair

Alternatively every value object can be cast into a string and recreated from it:

use Hawk\HawkiCrypto\AsymmetricCrypto;

$crypto = new AsymmetricCrypto();
$keypair = $crypto->generateKeypair();

echo (string) $keypair; // Outputs string representation of the keypair

$keypairFromString = AsymmetricKeypair::fromString((string) $keypair); // Recreates keypair from string

Exception Handling

The library throws exceptions that implement HawkiCryptoExceptionInterface when errors occur.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-07-08