脚本宝典收集整理的这篇文章主要介绍了php – 提供的密钥参数不能通过Google API强制转换为私钥,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
表达的所有常量都有正确的值,路径正确且没有空内容.
我得到的错误:
oPEnssl_sign(): supplied key param cannot be coerced into a PRivate key
我实现的功能是:
public static function storageURL( $id,$method = 'GET',$duration = 10 ) { $key = file_get_contents(self::KEY_FILE); $pkey = openssl_get_privatekey($key,'notasecret'); $expires = time( ) + $duration; $content_type = ($method == 'PUT') ? 'application/x-www-form-urlencoded' : ''; $to_sign = ($method . "\n" . /* Content-MD5 */ "\n" . $content_type . "\n" . $expires . "\n" . '/'.self::BUCKET_NAME.'/' . $id); $signature = '*Signature will go here*'; if (!openssl_sign( $to_sign,$signature,$pkey,'sha256' )) { error_LOG( 'openssl_sign Failed!' ); $signature = '<Failed>'; } else { $signature = urlencode( base64_encode( $signature ) ); } return ('https://'.self::BUCKET_NAME.'.COMmondatastorage.googleapis.com/' . $id . '?GoogleAccessId=' . self::SERVICE_ACCOUNT_NAME . '&Expires=' . $expires . '&Signature=' . $signature); }
我强烈建议您使用google-api-php-client,这是Google_P12Signer.php
以上是脚本宝典为你收集整理的php – 提供的密钥参数不能通过Google API强制转换为私钥全部内容,希望文章能够帮你解决php – 提供的密钥参数不能通过Google API强制转换为私钥所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。