Giter Site home page Giter Site logo

phpaes's Introduction

PhpAes

Build Status

FIPS-192 compliant AES cipher.

Supported key lengths:

  • 128 bits
  • 192 bits
  • 256 bits

Support block modes:

  • ECB: Electronic Code Book
  • CBC: Cipher Block Chaining
  • CFB: Cipher Feedback
  • OFB: Output Feedback

Supported padding schemes:

  • null byte (0x00)

Installation

Install via composer:

composer require phpaes/phpaes

Basic Usage

use PhpAes\Aes;

$aes = new Aes('abcdefgh01234567', 'CBC', '1234567890abcdef');

$y = $aes->encrypt('hello world!');
$x = $aes->decrypt($y);

echo base64_encode($y);
echo $x;

Static Code Analysis

Running Tests

vendor/bin/phpunit

Code Style

This project adheres to PSR-2 formatting.

vendor/bin/phpcs --extensions=php --report=summary --standard=PSR2 ./src ./tests

phpaes's People

Contributors

clphillips avatar

Stargazers

Akbarali avatar  avatar Farid Shishebori avatar Ahmad Syafiq avatar  avatar Anthony Diaz avatar Dessy Rizky avatar 上官江 avatar Sergio N. avatar Atlas Chiew avatar Iulian Roman avatar  avatar Alexey Gusev avatar  avatar  avatar Piyarid_Oven avatar Mohsen Davari avatar Ben avatar Lenix avatar rifk01 avatar kagasu avatar  avatar  ShaoBo Wan(無尘) avatar  avatar  avatar  avatar fx-fusion avatar  avatar  avatar Latte macchiato avatar Piotr Kaniuk avatar Paul Allen avatar Pathfinder - Chris Barlow avatar Guest avatar Ba'tiar Afas Rahmamulia avatar Light avatar fitoe avatar SunShare avatar Lorilee Treutel avatar Chris Cromer avatar  avatar luoyt avatar Tyler Richards avatar Albo Vieira avatar  avatar  avatar

Watchers

 avatar  avatar James Cloos avatar  avatar  avatar  avatar ryanclover avatar Iran app | ایران اپ avatar  avatar

phpaes's Issues

AES and PHP 7.3.3

I've been using AES on PHP 5.x for some time, but now my servers are being updated to PHP 7.3.3.
I tested my existing setup on 7.3.3, and using CBC mode (which is required) validation was failing.
No error messages are shown.
I set up a test on 7.3.3 which prints out the encrypted and decrypted outputs and the decrypted output still looks encrypted
The only clue I've found relates to changes in "__construct", but I don't know enough to decide if that may be the problem.
A demo is at:
http://fyefield.com/php_aes/aes_demo.php
GeeDeeJay

Changed behaviour of old version across PHP versions

I ran into something like #4 / #8 recently when I moved an older app to new hosting; figured I'd document my process in tracking the issue down here. I was using a version of AES.class.php dated October 1, 2007, and the old hosting was PHP5.4. (Don't laugh!)

<?php

include 'Aes2007.php';
include 'Aes2018.php';

use AES as Aes2007;
use PhpAes\Aes as Aes2018;

$key = 'abcdefgh01234567';
$secret = 'Hello, world!';

$aes2007 = new Aes2007($key);
$enc2007 = $aes2007->encrypt($secret);

$aes2018 = new Aes2018($key);
$enc2018 = $aes2018->encrypt($secret);

echo 'MD5 2007: ' . md5($enc2007) . PHP_EOL;
echo 'MD5 2018: ' . md5($enc2018) . PHP_EOL;
$ for VERSION in 5.4 5.5 5.6 7.0 7.1 7.2 7.3 7.4 8.0 ; do echo Testing with PHP $VERSION ; docker run --rm -v `pwd`:/app php:$VERSION php /app/aes-test.php ; echo ; done
Testing with PHP 5.4
MD5 2007: f0ad7ccf34653a5229ae9ab4c9fdf8b0
MD5 2018: f0ad7ccf34653a5229ae9ab4c9fdf8b0

Testing with PHP 5.5
MD5 2007: f0ad7ccf34653a5229ae9ab4c9fdf8b0
MD5 2018: f0ad7ccf34653a5229ae9ab4c9fdf8b0

Testing with PHP 5.6
MD5 2007: f0ad7ccf34653a5229ae9ab4c9fdf8b0
MD5 2018: f0ad7ccf34653a5229ae9ab4c9fdf8b0

Testing with PHP 7.0
MD5 2007: f0ad7ccf34653a5229ae9ab4c9fdf8b0
MD5 2018: f0ad7ccf34653a5229ae9ab4c9fdf8b0

Testing with PHP 7.1
MD5 2007: b3bb9a36713bdc2dde76139d23eb0d03
MD5 2018: f0ad7ccf34653a5229ae9ab4c9fdf8b0

Testing with PHP 7.2
MD5 2007: b3bb9a36713bdc2dde76139d23eb0d03
MD5 2018: f0ad7ccf34653a5229ae9ab4c9fdf8b0

Testing with PHP 7.3
MD5 2007: b3bb9a36713bdc2dde76139d23eb0d03
MD5 2018: f0ad7ccf34653a5229ae9ab4c9fdf8b0

Testing with PHP 7.4
MD5 2007: b3bb9a36713bdc2dde76139d23eb0d03
MD5 2018: f0ad7ccf34653a5229ae9ab4c9fdf8b0

Testing with PHP 8.0
Warning: Only the first byte will be assigned to the string offset in /app/Aes2007.php on line 1421 (repeated a lot of times)
MD5 2007: b3bb9a36713bdc2dde76139d23eb0d03
MD5 2018: f0ad7ccf34653a5229ae9ab4c9fdf8b0

For completeness, I'll document the original AES.class.php in the next comment.

My takeaway was that the class behaviour should be consistent if I swap to using the updated class in the new environment, but that the original class (older than the initial commit in this repo) changes behaviour between PHP7.0 and PHP7.1.

Use 128 bit or 256

Hi
Can i define bit size (128,256) before encrypt or decrypt?
Is the current 128 bit?
Thanks

way old AES.class.php

I have your way old class from Oct 1, 2007. This older class doesn't seem to be compatible with other libraries to decrypt AES128 not was i able to just drop in this newer class to replace it. I'm thinking i need to decrypt with the older class and then re-encrypt with the newer one to get some compatibility?

Use exception instead of die

Hi,

could you please use an exception instead of die function in case the configuration contains errors?

Kind regards

Michael

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.