phicorp/cipher 问题修复 & 功能扩展

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

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

phicorp/cipher

最新稳定版本:1.0.3

Composer 安装命令:

composer require phicorp/cipher

包简介

Cipher: A tool for easier working with cryptography for PHP language

README 文档

README

A tool for easier working with cryptography for PHP language

Installation

Install Cipher with composer

composer require phicorp/cipher

Features

  • Easy to use
  • Symmetric encryption and decryption with powerful AES algorithm
  • Asymmetric encryption and decryption with RSA algorithm
  • A variety of hash algorithms such as SHA and Bcrypt
  • And more features

Usage/Examples

  • Symmetric encryption and decryption:
$key = Cipher::AESKEY();
$iv = Cipher::AESIV();

$plaintext = 'Hello World!';

$ciphertext = encrypt($plaintext, $key, $iv);

$decryptedText = decrypt($ciphertext, $key, $iv);

echo "Original: $plaintext\n";
echo "Encrypted: $ciphertext\n";
echo "Decrypted: $decryptedText\n";

Or

$key = Cipher::AESKEY();
$iv = Cipher::AESIV();

$plaintext = 'Hello World!';

$ciphertext = Cipher::AES()->key($key)->iv($iv)->encrypt($plaintext);

$decryptedText = Cipher::AES()->key($key)->iv($iv)->decrypt($ciphertext);

echo "Original: $plaintext\n";
echo "Encrypted: $ciphertext\n";
echo "Decrypted: $decryptedText\n";
  • GCM Mode symmetric encryption and decryption
$key = Cipher::AESKEY("AES-256-GCM");
$iv = Cipher::AESIV();
$tag = null;

$plaintext = 'Hello World!';

$ciphertext = Cipher::AES('GCM')->key($key)->iv($iv)->encrypt($plaintext, 0, $tag);

$decryptedText = Cipher::AES('GCM')->key($key)->iv($iv)->decrypt($ciphertext, 0, $tag);

echo "Original: $plaintext\n";
echo "Encrypted: $ciphertext\n";
echo "Decrypted: $decryptedText\n";
  • Examples for asymmetric encryption and decryption
[$publicKey, $privateKey] = Cipher::RSAKEY();

$plaintext = 'hello world!';

$ciphertext = RSA($publicKey, $privateKey)->encryptPublic($plaintext);
$decryptedText = RSA($publicKey, $privateKey)->decryptPrivate($ciphertext);

echo "Original: $plaintext\n";
echo "Encrypted: $ciphertext\n";
echo "Decrypted: $decryptedText\n";

// You can also use it in this way

[$publicKey, $privateKey] = Cipher::RSAKEY();

$plaintext = 'hello world!';

$ciphertext = Cipher::RSA()->privateKey($privateKey)->encryptPrivate($plaintext);
$decryptedText = RSA()->publicKey($publicKey)->decryptPublic($ciphertext);

echo "Original: $plaintext\n";
echo "Encrypted: $ciphertext\n";
echo "Decrypted: $decryptedText\n";
  • Example of using hash functions
sha512('Hello World!');
//output: 861844d6704e...
sha256('Hello World!');
//output: 7f83b1657ff1...
$hash = bcrypt('password', 15);

var_dump(bcrypt_verify('password', $hash));
// output: true

Authors

License

MIT

统计信息

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

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-10-05