PHP's AES (Advanced encryption Standard Advanced Encryption Standard) encryption
AES introduces the Advanced encryption Standard (Advanced Encryption Standard, abbreviation: AES), which is also called Rijndael encryption method in cryptography. It is a block encryption standard adopted by the federal government of the United States.
This standard, which is used to replace the original DES, has been analyzed by many parties and is widely used all over the world.
After a five-year selection process, the Advanced encryption Standard was issued by the National Institute of Standards and Technology (NIST) in FIPS PUB 197 on November 26th, 2001, and became a valid standard on May 26th, 2002.
In 2006, the advanced encryption standard has become one of the most popular algorithms in symmetric key encryption.
Class AES {public $method ='; public $key =''; public $iv =''; public function _ _ construct (string $method, string $key, string $iv) {if (! in_array ($method, openssl_get_cipher_methods () {throw new\ Exception ($method. ' Encryption method is not support.');} $this- > method = $method; $this- > key = $key; $this- > iv = $iv;} / / AES encryption public function aesEncryption (string $data): string {$result = openssl_encrypt ($data, $this- > method, $this- > key, OPENSSL_RAW_DATA, $this- > iv); return base64_encode ($result) } / / AES decryption public function aesDecryption (string $data): string {return openssl_decrypt (base64_decode ($data), $this- > method, $this- > key, OPENSSL_RAW_DATA, $this- > iv);} $config = ['AES-128-CBC1', / / method encryption # AES-256-CBC, etc.' helloworld', / / key encryption key md5 (time ()). Uniqid (), true), / / iv guarantee offset is 16 bits]; try {$obj = new AES (. $config); echo $encryptionResult = $obj- > aesEncryption ('Jack'). PHP_EOL; echo $decryptionResult = $obj- > aesDecryption ($encryptionResult). PHP_EOL;} catch (\ Exception $e) {exit ($e-> getMessage () .PHP_EOL);}