123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- /**
- * AES.php UTF-8
- *
- *
- * @date : 2021-03-10 17:29
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : luowei <lw@huosdk.com>
- * @version : HUOSDK 9.0
- */
- namespace huoIdentify\controller;
- class AesEcb {
- /**
- * key
- *
- * @var string
- */
- private $key;
- /**
- * method
- *
- * @var string
- */
- private $cipher;
- /**
- * iv length
- *
- * @var int
- */
- private $ivlen;
- /**
- * AES constructor.
- *
- * @param $key
- * @param string $cipher
- */
- public function __construct($key, $cipher = 'aes-128-ecb') {
- $this->cipher = $cipher;
- $this->key = $key;
- }
- /**
- *
- * @param $cipherText
- *
- * @return string|false
- */
- public function decrypt($cipherText) {
- return openssl_decrypt($cipherText, $this->cipher, $this->key, OPENSSL_RAW_DATA);
- }
- /**
- *
- * @param string $plainText
- *
- * @return string
- */
- public function encrypt($plainText) {
- $result = openssl_encrypt($plainText, $this->cipher, $this->key, OPENSSL_RAW_DATA);
- return bin2hex($result);
- }
- }
|