dittertp/gibberish-aes-php

AES加密库

4.0.0 2022-09-19 20:49 UTC

This package is auto-updated.

Last update: 2024-09-20 11:28:25 UTC


README

Tests Scrutinizer Code Quality Code Coverage

Gibberish AES,PHP实现

查看Gibberish AES JavaScript加密库,https://github.com/mdp/gibberish-aes

重要提示:互补的JavaScript项目Gibberish AES已被弃用,见mdp/gibberish-aes#25
请考虑寻找替代的PHP和JavaScript解决方案。

此类基于由nbari在dalmp dot com提出的初始代码https://php.ac.cn/manual/en/function.openssl-decrypt.php#107210

在线演示

http://iridadesign.com/starter-public-edition-4/www/playground/gibberish-aes

要求

php >= 7.1

openssl和mbstring模块

使用示例

echo '<br />';

// This is a secret pass-phrase, keep it in a safe place and don't loose it.
$pass = 'my secret pass-phrase, it should be long';
echo '$pass = '.$pass;
echo '<br />';
// The string to be encrypted.
$string = 'my secret message';
echo '$string = '.$string;
echo '<br />';
echo '<br />';

// The default key size is 256 bits.
$old_key_size = GibberishAES::size();

echo 'Encryption and decryption using a 256-bit key:';
echo '<br />';
GibberishAES::size(256);
// This is the result after encryption of the given string.
$encrypted_string = GibberishAES::enc($string, $pass);
// This is the result after decryption of the previously encrypted string.
// $decrypted_string == $string (should be).
$decrypted_string = GibberishAES::dec($encrypted_string, $pass);
echo '$encrypted_string = '.$encrypted_string;
echo '<br />';
echo '$decrypted_string = '.$decrypted_string;
echo '<br />';
echo '<br />';

echo 'Encryption and decryption using a 192-bit key:';
echo '<br />';
GibberishAES::size(192);
$encrypted_string = GibberishAES::enc($string, $pass);
$decrypted_string = GibberishAES::dec($encrypted_string, $pass);
echo '$encrypted_string = '.$encrypted_string;
echo '<br />';
echo '$decrypted_string = '.$decrypted_string;
echo '<br />';
echo '<br />';

echo 'Encryption and decryption using a 128-bit key:';
echo '<br />';
GibberishAES::size(128);
$encrypted_string = GibberishAES::enc($string, $pass);
$decrypted_string = GibberishAES::dec($encrypted_string, $pass);
echo '$encrypted_string = '.$encrypted_string;
echo '<br />';
echo '$decrypted_string = '.$decrypted_string;
echo '<br />';
echo '<br />';

// Restore the old key size.
GibberishAES::size($old_key_size);

作者:Ivan Tcholakov,2012-2016。

作者:Philipp Dittert,2019-2020。

许可:MIT许可 (MIT),http://opensource.org/licenses/MIT

部分代码受新BSD许可,George Argyros,2012。

安装

您可以通过将以下片段添加到composer.json来使用库

{
    "require": {
        "dittertp/gibberish-aes-php" : "^2.0"
    },
}

运行代码风格检查

composer update
vendor/bin/phpcs --standard=PSR12 src/

运行单元测试

composer update
vendor/bin/phpunit --bootstrap bootstrap.php --configuration phpunit.xml