实用的PHP算法AES加密解密类之OpenSSL (复制可用)

IT-Pony 2018-09-07 PM 1707℃ 0条

代码部分

    <?php

    class Aes {
        CONST OPTIONS = OPENSSL_RAW_DATA;
    
        /**
         * @param $input
         * @param string $keys
         * @param string $cipher
         * @return string
         */
        public static function encrypt($input, $keys = '', $cipher = 'AES-128-ECB')
        {
            if(empty($keys)) $keys = self::$keys;
            $data = openssl_encrypt($input, $cipher, $keys, self::OPTIONS);
            return bin2hex($data);
        }
    
        /**
         * @param $output
         * @param string $keys
         * @param string $cipher
         * @return string
         */
        public static function decrypt($output, $keys = '', $cipher = 'AES-128-ECB')
        {
            if(empty($keys)) $keys = self::$keys;
    
            $data = hex2bin($output);
            return openssl_decrypt($data, $cipher, $keys, self::OPTIONS);
        }
    }

使用方法

    
    Aes::encrypt('需要加密的数据');       
标签: none

非特殊说明,本博所有文章均为博主原创。

评论啦~