收藏
回答

获取密文后,经sha1之后与获取的signature相比较,偶尔相等,大多数不相等,为什么?

获取密文后,经sha1之后与获取的signature相比较,偶尔相等,大多数不相等,为什么?

public function decryptMsg($msgSignature, $timestamp, $nonce, $postData, &$msg)

{

if (strlen($this->encodingAesKey) != 43) {

return ErrorCode::$IllegalAesKey;

}

$pc = new Prpcrypt();

$pc->Prpcrypt($this->encodingAesKey);

//提取密文

$xmlparse = new XMLParse;

$array = $xmlparse->extract($postData);

$ret = $array[0];

if ($ret != 0) {

return $ret;

}

if ($timestamp == null) {

$timestamp = time();

}


$encrypt = $array[1];

$touser_name = $array[2];

$arr = [$this->token, $timestamp, $nonce,$encrypt];

sort($arr);

$signature = sha1(implode($arr));

//此处$signature与$msgSignature经常不相等,为什么

if ($signature != $msgSignature) {

return ErrorCode::$ValidateSignatureError;

}

$result = $pc->decrypt($encrypt, $this->appId);

if ($result[0] != 0) {

return $result[0];

}

$msg = $result[1];


return ErrorCode::$OK;

}

回答关注问题邀请回答
收藏

1 个回答

登录 后发表内容