<i id='AEqJP'><tr id='AEqJP'><dt id='AEqJP'><q id='AEqJP'><span id='AEqJP'><b id='AEqJP'><form id='AEqJP'><ins id='AEqJP'></ins><ul id='AEqJP'></ul><sub id='AEqJP'></sub></form><legend id='AEqJP'></legend><bdo id='AEqJP'><pre id='AEqJP'><center id='AEqJP'></center></pre></bdo></b><th id='AEqJP'></th></span></q></dt></tr></i><div id='AEqJP'><tfoot id='AEqJP'></tfoot><dl id='AEqJP'><fieldset id='AEqJP'></fieldset></dl></div>

      <legend id='AEqJP'><style id='AEqJP'><dir id='AEqJP'><q id='AEqJP'></q></dir></style></legend>

        <small id='AEqJP'></small><noframes id='AEqJP'>

          <bdo id='AEqJP'></bdo><ul id='AEqJP'></ul>
      1. <tfoot id='AEqJP'></tfoot>
      2. 使用 php 进行三重 DES 加密/解密

        时间:2023-12-01
        <tfoot id='tlXkY'></tfoot>
        <legend id='tlXkY'><style id='tlXkY'><dir id='tlXkY'><q id='tlXkY'></q></dir></style></legend>
            <tbody id='tlXkY'></tbody>
          1. <i id='tlXkY'><tr id='tlXkY'><dt id='tlXkY'><q id='tlXkY'><span id='tlXkY'><b id='tlXkY'><form id='tlXkY'><ins id='tlXkY'></ins><ul id='tlXkY'></ul><sub id='tlXkY'></sub></form><legend id='tlXkY'></legend><bdo id='tlXkY'><pre id='tlXkY'><center id='tlXkY'></center></pre></bdo></b><th id='tlXkY'></th></span></q></dt></tr></i><div id='tlXkY'><tfoot id='tlXkY'></tfoot><dl id='tlXkY'><fieldset id='tlXkY'></fieldset></dl></div>

            <small id='tlXkY'></small><noframes id='tlXkY'>

              <bdo id='tlXkY'></bdo><ul id='tlXkY'></ul>

                • 本文介绍了使用 php 进行三重 DES 加密/解密的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在 PHP 中有这个三重 DES 加密代码

                  I have this TRIPLE DES ENCRYPTION CODE IN PHP

                      $encryption_key = "CE51E06875F7D964";
                      $data='tokenNo=test&securityCode=111' ;
                      echo $desEncryptedData = encryptText_3des($data, $encryption_key);//outputs 3des encrypted data
                  
                  function encryptText_3des($plainText, $key) {
                      $key = hash("md5", $key, TRUE); 
                      for ($x=0;$x<8;$x++) {
                          $key = $key.substr($key, $x, 1);
                      }
                      $padded = pkcs5_pad($plainText,
                          mcrypt_get_block_size(MCRYPT_3DES, MCRYPT_MODE_CBC));
                      $encrypted = base64_encode(mcrypt_encrypt(MCRYPT_3DES, $key, $padded, MCRYPT_MODE_CBC));
                      return $encrypted;
                  }
                   function pkcs5_pad ($text, $blocksize)   
                  {
                      $pad = $blocksize - (strlen($text) % $blocksize);
                      return $text . str_repeat(chr($pad), $pad);
                  }
                  

                  我能够将数据加密为 xcFEvIdLXc2fjhG1i4iPOQu5L6ahxwZVucDOPqeMM2E=

                  现在我有了密钥,我可以将这些数据解密为纯文本格式吗?

                  Now I have the key,will I able to decrypt this data to plain text format?

                  我试过这样

                              $encryption_key = "CE51E06875F7D964";
                          $data='xcFEvIdLXc2fjhG1i4iPOQu5L6ahxwZVucDOPqeMM2E=' ; //encrypted data
                          echo $desEncryptedData = encryptText_3des($data, $encryption_key);//outputs 3des encrypted data
                  
                      function encryptText_3des($plainText, $key) {
                          $key = hash("md5", $key, TRUE); 
                          for ($x=0;$x<8;$x++) {
                              $key = $key.substr($key, $x, 1);
                          }
                          $padded = pkcs5_unpad($plainText,
                              mcrypt_get_block_size(MCRYPT_3DES, MCRYPT_MODE_CBC));
                          $encrypted = base64_encode(mcrypt_encrypt(MCRYPT_3DES, $key, $padded, MCRYPT_MODE_CBC));
                          return $encrypted;
                      }
                  
                      function pkcs5_unpad($text)   
                  
                      {
                          $pad = ord($text{strlen($text)-1});
                          if ($pad > strlen($text)) return false;
                          if (strspn($text, chr($pad), strlen($text) - $pad) != $pad) return false;
                          return substr($text, 0, -1 * $pad);
                      }
                  

                  但我做不到.是我做错了吗?请建议我一种解密方法?加密密钥本身是否用于解密三重 DES 中的数据?请帮助

                  But I couldnt do it.IS what I am doing is wrong?Please suggest me a way to decrypt this?Is the encryption key itself is used to decrypt the data in triple DES?Please help

                  推荐答案

                  PHP 7.1 及以上版本,mcrypt 功能已弃用.这是使用 openssl_encrypt

                  For PHP 7.1 and above, mcrypt function is deprecated. Here is the alternative using openssl_encrypt

                  $ciphertext = openssl_encrypt('string to be encrypted', 'DES-EDE3', 'key', OPENSSL_RAW_DATA);
                  $ciphertext = base64_encode($ciphertext);
                  

                  您可以使用此在线三重DES加密工具交叉检查.

                  You can use this online Triple DES encryption tool to cross check.

                  对于其他可用的密码,您可以调用 PHP 方法 openssl_get_cipher_methods()

                  For other available cipher, you can invoke PHP method openssl_get_cipher_methods()

                  这篇关于使用 php 进行三重 DES 加密/解密的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:C# SHA-1 与 PHP SHA-1 ...不同的结果? 下一篇:随机睡眠可以防止定时攻击吗?

                  相关文章

                  <tfoot id='novKS'></tfoot>

                • <i id='novKS'><tr id='novKS'><dt id='novKS'><q id='novKS'><span id='novKS'><b id='novKS'><form id='novKS'><ins id='novKS'></ins><ul id='novKS'></ul><sub id='novKS'></sub></form><legend id='novKS'></legend><bdo id='novKS'><pre id='novKS'><center id='novKS'></center></pre></bdo></b><th id='novKS'></th></span></q></dt></tr></i><div id='novKS'><tfoot id='novKS'></tfoot><dl id='novKS'><fieldset id='novKS'></fieldset></dl></div>
                    • <bdo id='novKS'></bdo><ul id='novKS'></ul>
                      <legend id='novKS'><style id='novKS'><dir id='novKS'><q id='novKS'></q></dir></style></legend>

                      <small id='novKS'></small><noframes id='novKS'>