Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# PHPSHA1编码方式与c不同#_C#_Php - Fatal编程技术网

C# PHPSHA1编码方式与c不同#

C# PHPSHA1编码方式与c不同#,c#,php,C#,Php,我知道这是一个问题,c#和php对sha1哈希进行编码的方式不同,但我找不到php版本的c#sha1的示例 c#代码: php: $hashedSupplierPrivateKey = $supplierPrivateKey.gmdate("Y/m/d H:i:s"); $hashedSupplierPrivateKey = utf8_encode($hashedSupplierPrivateKey); $hashedSupplierPrivateKey = sha1($hashe

我知道这是一个问题,c#和php对sha1哈希进行编码的方式不同,但我找不到php版本的c#sha1的示例

c#代码:

php:

 $hashedSupplierPrivateKey = $supplierPrivateKey.gmdate("Y/m/d H:i:s");


  $hashedSupplierPrivateKey = utf8_encode($hashedSupplierPrivateKey);
  $hashedSupplierPrivateKey = sha1($hashedSupplierPrivateKey,true);

    //Error here

     $hashedSupplierPrivateKey = str_replace("-", "", $hashedSupplierPrivateKey);

     $hashedSupplierPrivateKey = strtoupper($hashedSupplierPrivateKey);
     echo $hashedSupplierPrivateKey;
下面是一个用c生成的正确哈希的示例#


我认为您在c#中获得原始字节,而在php中,默认情况下,sha1()返回十六进制。您可以将true作为第二个参数传递给php的sha1(),以获取原始字节。或者转换为c#中的十六进制。

发布PHP和c#@ShankarDamodaran中的纯文本和密码,使用示例和完整的codeIs参数
now
使用
DateTime.now
(不正确)或
DateTime.UtcNow
?在PHP日期格式中是“Y-m-DH:i:s”,在c#中是“YYYYY/MM/dd HH:MM:ss”我很确定他们会退回同样的东西。不,他们不会。c#中的斜杠,php中的破折号<代码>“1111/22/33”!=“1111-22-33”我更改了日期格式,使它们匹配,但仍然无法工作。
 $hashedSupplierPrivateKey = $supplierPrivateKey.gmdate("Y/m/d H:i:s");


  $hashedSupplierPrivateKey = utf8_encode($hashedSupplierPrivateKey);
  $hashedSupplierPrivateKey = sha1($hashedSupplierPrivateKey,true);

    //Error here

     $hashedSupplierPrivateKey = str_replace("-", "", $hashedSupplierPrivateKey);

     $hashedSupplierPrivateKey = strtoupper($hashedSupplierPrivateKey);
     echo $hashedSupplierPrivateKey;
      530DFA9CD08CF36017B7C781E1A8D0CEC74CB944