aes加密解密 版本二 无末尾占位符

正文开始

[md]


<?php /** * 消息内容加解密 */ class MsgAes { // 密码学方式,不可更改 private static $method = \'AES-128-CBC\'; // 加密 public static function encrypt($aesKey, $data) { $ivLen = openssl_cipher_iv_length(self::$method); $iv = openssl_random_pseudo_bytes($ivLen); $encryptedStr = openssl_encrypt($data, self::$method, $aesKey, OPENSSL_RAW_DATA, $iv); return base64_encode($iv . $encryptedStr); } // 解密 public static function decrypt($aesKey, $encryptedData) { $encryptedData = base64_decode($encryptedData); $ivLen = openssl_cipher_iv_length(self::$method); $iv = substr($encryptedData, 0, $ivLen); $encryptedStr = substr($encryptedData, $ivLen); $decryptedStr = openssl_decrypt($encryptedStr, self::$method, $aesKey, OPENSSL_RAW_DATA, $iv); return $decryptedStr; } }

正文结束

PHP接口(interface)和抽象类(abstract) php 科学计数法转化正常数值输出 解决方案