Php 计费应用程序和";openssl_verify():无法将提供的密钥参数强制转换为公钥;
我正在尝试测试我的服务器端IAB签名验证方法。我想使用我的公钥和私钥(不是谷歌的),所以我伪造收据并用id_rsa.pub签名:Php 计费应用程序和";openssl_verify():无法将提供的密钥参数强制转换为公钥;,php,openssl,rsa,in-app-billing,php-openssl,Php,Openssl,Rsa,In App Billing,Php Openssl,我正在尝试测试我的服务器端IAB签名验证方法。我想使用我的公钥和私钥(不是谷歌的),所以我伪造收据并用id_rsa.pub签名: openssl dgst -binary -sha1 -sign /Users/user/.ssh/id_rsa receipt.json | openssl base64 > signature.txt 在php中,我想用openssl\u验证: $publicKey = // content of /Users/user/.ssh/id_rsa.pub
openssl dgst -binary -sha1 -sign /Users/user/.ssh/id_rsa receipt.json | openssl base64 > signature.txt
在php中,我想用openssl\u验证:
$publicKey = // content of /Users/user/.ssh/id_rsa.pub
// Public key in id_rsa.pub with proper header and footer
$publicKeyFull = "-----BEGIN PUBLIC KEY-----\n" . chunk_split($publicKey, 64, "\n") . "-----END PUBLIC KEY-----";
// Data
$data = // content of receipt.json WITHOUT LINE BREAKS
// Public key id
$publicKeyId = openssl_get_publickey($publicKeyFull);
// Signature
$signature = // content of signature.txt generated previously
// receipt.json, signature.txt, id_rsa.public
$verified = openssl_verify($data, base64_decode($signature), $publicKeyId, OPENSSL_ALGO_SHA1);
var_dump($verified);
验证总是错误的,我得到:
Warning: openssl_verify(): supplied key param cannot be coerced into a public key in...
我的id_rsa.pub密钥有什么问题?您传递的$verified错误,正如@awnry bear提到的相同类型的错误 请检查以下内容:
可能重复、和可能重复我传递的错误是什么?在您链接的答案中,OP传递的是purchaseToken…我传递的是正确的整个JSON。您的错误消息显示$publicKey没有被正确读取,应该插入一个值,而不是向aa文件添加一个链接,这样就可以将文件的值解析为$publicKey,这样应该可以正常工作。