adeotek / gibberish-aes-php
Gibberish AES,PHP实现
v1.3.5
2021-04-29 12:26 UTC
Requires
- php: >=7.1
- lib-openssl: >=1.0.1
This package is not auto-updated.
Last update: 2024-09-28 03:20:08 UTC
README
查看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
要求
- 已安装OpenSSL函数,且PHP版本 >= 5.3.3
或
- 已安装Mcrypt函数,且PHP版本 < 7.1.0-alpha
对于PHP版本低于7的情况,建议你在项目中安装"PHP 5.x support for random_bytes() and random_int()",https://github.com/paragonie/random_compat
使用示例
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。
许可:MIT许可(MIT),https://open-source.org.cn/licenses/MIT
部分代码在New BSD许可下,George Argyros,2012。