ciphertext = lQUHa/d5lTEvHOgbNwE4lgaVQ6ig1kIpUzMJ6RWi5TTAOZhy76OX475C/YHfYkGe4b4dVMZPdYKBfvjFLGAe1/v1eJLo9AEA7wyTY7eKFcvTnDc4WDMCWKaZcDKEDmEZMWibXotS2R78WLROpU89ylWH2fhJvhWk4BYcpfNxe2UpBklBByhZp4zhbl6NBVoMiE8BlrTNjoh7uISVf0PNZibiGzSBdrHn+kyURDoQ+xTyhUJbGN9hZ5d4wJcSAuTbVfawrDAfEq7UpL84oNs+Uzvwxc2UHNkBEqozuflSTPP7siiGPAS//j5GGpH4jjCejV9b9aqQyK8jJH+yEq9B9oiDEaUxW7avBlgBVk9TKRCAI8Gf075a7Gg2BNDJSxS2WPfBmJ12InW1ImGJ5Bh0HMsCwO/23NA+3xTXHBtfqJo4WyGZ21Jw+XlBEaePC1W3wfo3YCSBUxA1OUnaccKQtQddGMXwO8GpCLBbbIIOlUZTW8yit4K5glAHY3Po3e2zSLHLGr14bDdqQNgKTZdySUGHhLz2vAfH46M= associatedData = refund nonceStr = mX80szDPRumd aeskey = 94944cbdb0ceefe457f5f7ae708847eb 是哪一步出现问题?sodium和openssl_decode都无法解密
/** * Takes a base64 encoded string and decrypts it using a given key, iv and aad. * * @param string $ciphertext - The base64-encoded ciphertext. * @param string $key - The secret key, 32 bytes string. * @param string $iv - The initialization vector, 16 bytes string. * @param string $aad - The additional authenticated data, maybe empty string. * * @return string - The utf-8 plaintext. */ public static function decrypt(string $ciphertext, string $key, string $iv = '', string $aad = ''): string { $ciphertext = base64_decode($ciphertext); $authTag = substr($ciphertext, intval(-static::BLOCK_SIZE)); $tagLength = strlen($authTag); /* Manually checking the length of the tag, because the `openssl_decrypt` was mentioned there, it's the caller's responsibility. */ if ($tagLength > static::BLOCK_SIZE || ($tagLength < 12 && $tagLength !== 8 && $tagLength !== 4)) { throw new RuntimeException('The inputs `$ciphertext` incomplete, the bytes length must be one of 16, 15, 14, 13, 12, 8 or 4.'); } $plaintext = openssl_decrypt(substr($ciphertext, 0, intval(-static::BLOCK_SIZE)), static::ALGO_AES_256_GCM, $key, OPENSSL_RAW_DATA, $iv, $authTag, $aad); if (false === $plaintext) { throw new UnexpectedValueException('Decrypting the input $ciphertext failed, please checking your $key and $iv whether or nor correct.'); } return $plaintext; }
摘自 composer require wechatpay/wechatpay
用法
\WeChatPay\Crypto\AesGcm::decrypt($resource['ciphertext'], $apiv3Key, $resource['nonce'], $resource['associated_data']);
你解密用的 `aeskey` 不是APIv3密钥
贴代码……还有报错信息……
光贴个微信回调数据上来,谁哪知道是哪报错了?