zoukankan      html  css  js  c++  java
  • php AES cbc模式 pkcs7 128位加密解密(微信小程序)

    PHP AES CBC模式PKCS7 128位加密

    加密:

            $key = '1234567812345678';
            $iv = '1234567890123456'; 
            $message = '123456';
            $blocksize = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
            $len = strlen($message); //取得字符串长度
            $pad = $blocksize - ($len % $blocksize); //取得补码的长度
            $message .= str_repeat(chr($pad), $pad); //用ASCII码为补码长度的字符, 补足最后一段
            $xcrypt = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $message, MCRYPT_MODE_CBC, $iv);

    PHP AES CBC模式PKCS7 128位解密

    解密:

    public function stripPkcs7Padding($string) {
            $slast = ord(substr($string, -1));
            $slastc = chr($slast);
            $pcheck = substr($string, -$slast);
     
            if (preg_match("/$slastc{" . $slast . "}/", $string)) {
                $string = substr($string, 0, strlen($string) - $slast);
                return $string;
            } else {
                return false;
            }
        }
     
    stripPkcs7Padding(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $xcrypt, MCRYPT_MODE_CBC, $iv))

     http://php.net/manual/zh/function.mcrypt-encrypt.php

    转: https://blog.csdn.net/u011650048/article/details/50846124

  • 相关阅读:
    OpenCV——IplImage
    OpenCV——常用函数查询
    OpenCV——Sobel和拉普拉斯变换
    OpenCV——CvSeq动态结构序列
    OpenCV——人脸检测
    Java—Integer类
    Java—NumberFormat与DecimalFormat类
    sql事务机制
    存储过程
    java中的抽象类和接口
  • 原文地址:https://www.cnblogs.com/fps2tao/p/10129681.html
Copyright © 2011-2022 走看看