This commit is contained in:
xl
2023-11-13 22:59:34 +08:00
parent ac4c6c1e27
commit 0eb8aab1d2
3 changed files with 4 additions and 23 deletions
+3 -2
View File
@@ -135,11 +135,12 @@ trait WxV3PaymentTait
/**
* @param string $ciphertext
* @param string $v3Key
* @param string $iv
* @param string $aad
* @return array
*/
public function decrypt(string $ciphertext, string $iv = '', string $aad = ''): array
public function decrypt(string $ciphertext, string $v3Key, string $iv = '', string $aad = ''): array
{
$ciphertext = base64_decode($ciphertext);
$authTag = substr($ciphertext, $tailLength = 0 - BLOCK_SIZE);
@@ -149,7 +150,7 @@ trait WxV3PaymentTait
if ($tagLength > 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, $tailLength), ALGO_AES_256_GCM, $this->getConfig()->getKey(), OPENSSL_RAW_DATA, $iv, $authTag, $aad);
$plaintext = openssl_decrypt(substr($ciphertext, 0, $tailLength), ALGO_AES_256_GCM, $v3Key, 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.');
}