public function index() { $rawText = I('post.rawtext', ''); $text = I('post.text', ''); // dump(base64_encode("hebidu")); // dump(base64_decode("aGViaWR1")); // $privateKey = "hebidu"; // $iv = ""; // $string = "hebidu"; $key = "136799711"; // dump(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $privateKey, $string, MCRYPT_MODE_CBC, $iv)); //IOS AES 加密 //kCCOptionPKCS7Padding | kCCOptionECBMode, // $encodeStr = "uYjVy+FbJqXi/Ep+9OtaXA=="; //kCCOptionPKCS7Padding | kCCOptionECBMode, //uYjVy+FbJqXi/Ep+9OtaXA== $encodeStr = ""; if (IS_POST && (!empty($rawText) || !empty($text))) { if (!empty($rawText)) { dump($rawText); $encodeStr = AES::encrypt($rawText, $key); $this->assign("text", $encodeStr); dump($encodeStr); } else { dump($text); $encodeStr = AES::decrypt($text, $key); dump($encodeStr); $this->assign("rawtext", $encodeStr); } } // // $encode = AES::encrypt($string,$key); // dump($encode); // $encode = AES::decrypt($encode,$key); // dump($encode); $this->display(); // $encode="o83EVYqKiopZVlReXUw="; // $encode = $crypt->AESDecryptCtr($encode,$key,128); // dump($encode); // $encode="o83EVYqKiopZVlReXUw="; // $crypt = new Des(); // $encode = $crypt->encrypt($string,$key,true); // $decode = $crypt->decrypt($encode,$key,true); // echo $encode; // echo "<br />"; // echo $decode; // // $decode = $crypt->decrypt($encodeStr,$key,true); // echo "<br />"; // echo $decode; }
public static function encrypt($input, $key) { if (!function_exists('mcrypt_get_block_size')) { throw new Exception("请安装mcrypt扩展库!"); } $size = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC); $input = AES::pkcs7_pad($input, $size); $td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, ''); $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND); $iv = "1234567812345678"; mcrypt_generic_init($td, $key, $iv); $data = mcrypt_generic($td, $input); mcrypt_generic_deinit($td); mcrypt_module_close($td); $data = base64_encode($data); return $data; }