使用phpseclib3库解密WhatsApp Flows响应时遇到‘Ciphertext representative too long’错误的求助
使用phpseclib3库解密WhatsApp Flows响应时遇到‘Ciphertext representative too long’错误的求助
各位好,我现在在开发WhatsApp Flows的响应解密功能,用的是PHP + CodeIgniter 4框架,搭配phpseclib3库来做加解密操作。但是运行代码的时候一直卡在解密AES密钥这一步,报出Ciphertext representative too long的错误,具体是在这一行:$decryptedAesKey = $rsa->decrypt($encryptedAesKey);
下面是我的示例代码:
private function decryptRequest($body, $privatePem) { $encryptedAesKey = base64_decode($body['encrypted_aes_key']); $encryptedFlowData = base64_decode($body['encrypted_flow_data']); $initialVector = base64_decode($body['initial_vector']); $rsa = RSA::load($privatePem) ->withPadding(RSA::ENCRYPTION_OAEP) ->withHash('sha256') ->withMGFHash('sha256'); $decryptedAesKey = $rsa->decrypt($encryptedAesKey); if (!$decryptedAesKey) { throw new Exception('Decryption of AES key failed.'); } $aes = new AES('gcm'); $aes->setKey($decryptedAesKey); $aes->setNonce($initialVector); $decrypted = $aes->decrypt($encryptedFlowData); if (!$decrypted) { throw new Exception('Decryption of flow data failed.'); } return [ 'decryptedBody' => json_decode($decrypted, true), 'aesKeyBuffer' => $decryptedAesKey, 'initialVectorBuffer' => $initialVector, ]; }
我已经查阅了WhatsApp官方的加密相关文档,但还是没找到解决这个错误的办法,有没有有经验的朋友能帮我排查下问题出在哪?
备注:内容来源于stack exchange,提问作者iam_furanki
相关产品推荐
相关产品推荐

