Supplied key param cannot be coerced into a private key with Google APIs

荒凉一梦 提交于 2019-11-27 15:35:53

First, you need to use openssl_pkcs12_read to read the key file, not file_get_contents. Second, I believe you want to leave off the second parameter to openssl_get_privatekey.

I highly recommend you use google-api-php-client for this, which has Google_P12Signer.php

The safer way is to use Google_Signer_P12 class shipped with Google API PHP client to do that.

Code sample:

set_include_path(get_include_path() . PATH_SEPARATOR . 'PATH/TO/API/src');
require_once 'Google/Signer/P12.php';

$p12contents = file_get_contents('FILE.p12');
$googleSigner = new Google_Signer_P12($p12contents, 'notasecret');
$signature = $googleSigner->sign($data);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!