lt / php-aes Goto Github PK
View Code? Open in Web Editor NEWPure PHP implementation of the AES cipher.
License: MIT License
Pure PHP implementation of the AES cipher.
License: MIT License
Awesome project.. but I noticed something strange when using AES in CTR mode with streamEncrypt for chunk encrypting/decrypting..
The first steamEncrypt works as expected but when calling a second one with the same encryptionContext the library goes into an infinite loop.
My code:
$key = new AES\Key('abcdefghijklmnop');
$nonce = 'abcdefghijklmnop';
$ctr = new AES\CTR;
$encryptionContext = $ctr->initEncryption($key, $nonce);
$plaintext0 = "Secret string part 1";
$plaintext1 = "Secret string part 2";
$ciphertext = $ctr->streamEncrypt($encryptionContext, $plaintext0);
$ciphertext .= $ctr->streamEncrypt($encryptionContext, $plaintext1);
$decryptionContext = $ctr->initDecryption($key, $nonce);
$result = $ctr->streamDecrypt($decryptionContext, $ciphertext);
var_dump($result);
I debugged some lines and I think it may be related to this line:
$bytesRequired = strlen($message) - strlen($keyStream);
(https://github.com/lt/PHP-AES/blob/master/lib/CTR.php#L43)
This will hold a negative value when the second call to streamEncrypt is made and thus cause the subsequent while loop to run forever:
while ($blockCount--) {
I think the solution may be to ABS the value in $bytesRequired but I don't know enough about crypto to be certain.
Help would be much appreciated. ;)
Hello! How can I use this lib ### without composer? Only require.
I need to use the following pattern for my AES:
How can I do it using this library?
So I fork this and fix this.
https://github.com/CornWorld/PHPAES
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.