<tfoot id='S7teO'></tfoot>

    1. <small id='S7teO'></small><noframes id='S7teO'>

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

      PHP中P_SHA1算法的实现

      时间:2023-05-22
      <tfoot id='uAe1v'></tfoot>

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

                <tbody id='uAe1v'></tbody>
                <legend id='uAe1v'><style id='uAe1v'><dir id='uAe1v'><q id='uAe1v'></q></dir></style></legend>
                本文介绍了PHP中P_SHA1算法的实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                我们正在尝试实现一个函数 P_SHA1 表示 PHP.用 Python 编写的函数的模式.但是,不幸的是,有些东西不能正常工作.下面是JAVA中的实现函数:http://ws.apache.org/wss4j/xref/org/apache/ws/security/conversation/dkalgo/P_SHA1.html

                we are trying to implement a function P_SHA1 means PHP. The pattern of the function written in Python. But, unfortunately, something is not working properly. Here is the implementation function in JAVA: http://ws.apache.org/wss4j/xref/org/apache/ws/security/conversation/dkalgo/P_SHA1.html

                我们的代码:

                <?php
                  $newSeed    = $label . $seed; // concat as strings
                  // $p_sha1
                  $psha1 = p_hash('sha1', $secret, $newSeed, $length);
                  $string = arrayToBytes($psha1);
                  /**
                  * P_SHA1 crypto alg calculation
                  *
                  * @return array of bytes - key
                  **/
                  function p_hash($algo, $secret, $seed, $length) {
                    $bytes = array_fill(0, $length, 0); 
                    $tmp = null;
                    $A = $seed;
                    $index = 0;
                
                    while (1) {
                      // hmac sha1: secret + seed
                      $A = hash_hmac($algo, $secret, $A, true);
                
                      // hmac sha1: secret + 1st hash + seed
                      $output = hash_hmac($algo, $secret, ($A . $seed), true);
                
                      foreach (bytesToArray($output) as $c) {
                          if ($index >= $length) {
                              return $bytes;
                          }
                
                          $bytes[$index] = $c;
                          $index++;
                      }
                    }
                    return $bytes;
                }
                
                function bytesToArray($bytes) { return unpack('C*', $bytes); }
                function arrayToBytes($array) { return call_user_func_array("pack", array_merge(array("C*"), $array)); }
                ?>
                

                也许有人知道我在哪里可以找到现成的解决方案?或者任何人都可以帮助编写脚本以使其正常工作?

                Maybe someone knows where I can find a ready-made solution? Or anyone can help make a script to work properly?

                推荐答案

                这是基于 回复通过签名 FS" SOAP 消息请求.我已经成功地使用它来签署 SOAP 请求并获得我想要的响应.

                This is based on the C# method included in a reply to "signing SOAP message request via ADFS". I have successfully used it to sign SOAP requests and get the response I want.

                function psha1($clientSecret, $serverSecret, $sizeBits = 256)
                {
                    $sizeBytes = $sizeBits / 8;
                
                    $hmacKey = $clientSecret;
                    $hashSize = 160; // HMAC_SHA1 length is always 160
                    $bufferSize = $hashSize / 8 + strlen($serverSecret);
                    $i = 0;
                
                    $b1 = $serverSecret;
                    $b2 = "";
                    $temp = null;
                    $psha = array();
                
                    while ($i < $sizeBytes) {
                        $b1 = hash_hmac('SHA1', $b1, $hmacKey, true);
                        $b2 = $b1 . $serverSecret;
                        $temp = hash_hmac('SHA1', $b2, $hmacKey, true);
                
                        for ($j = 0; $j < strlen($temp); $j++) {
                            if ($i < $sizeBytes) {
                                $psha[$i] = $temp[$j];
                                $i++;
                            } else {
                                break;
                            }
                        }
                    }
                
                    return implode("", $psha);
                }
                

                需要注意的重要一点是,客户端机密和服务器机密在传递给此函数之前应该进行 base64 解码.

                One thing of importance to note is that the client secret and server secret should be base64 decoded before being passed to this function.

                这篇关于PHP中P_SHA1算法的实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:将字节数组从 PHP 发送到 WCF 下一篇:PHP SoapClient:SoapFault 异常无法连接到主机

                相关文章

                最新文章

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

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

                  1. <legend id='kTLIt'><style id='kTLIt'><dir id='kTLIt'><q id='kTLIt'></q></dir></style></legend>