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

  • 相关阅读:
    Node 修改默认镜像源
    Mac下apache虚拟主机配置
    Grep命令出现 Binary file (standard input) matches
    idea取出方法参数提示
    Java8 Optional用法
    Codeforces Round #638 (Div. 2)
    Codeforces Round #637 (Div. 2)
    Codeforces Round #636 (Div. 3)
    Tree
    Educational Codeforces Round 85
  • 原文地址:https://www.cnblogs.com/fps2tao/p/10129681.html
Copyright © 2011-2022 走看看