openssl_pkey_get_details()期望参数1为资源,给定布尔值 [英] openssl_pkey_get_details() expects parameter 1 to be resource, boolean given

查看:887
本文介绍了openssl_pkey_get_details()期望参数1为资源,给定布尔值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在某处"找到了该脚本:

I've found this script "somewhere":

define("ACC_NAME", "my_steam_login");
define("ACC_PASS", "my_password");
define("GROUP_ID", "my_group_id"); // open steam group page and see "Enterchat room" link, which contains ID
define("MY_STEAM_ID", "my_steamid"); // steam ID which can invite to join group

$invite_steam_id = $_GET['i'];

$ids = file('invited_ids.txt');
foreach($ids as $id){
    $id = trim($id);
    if ( $id == $invite_steam_id )
        die($id .": Already invited!\n");
}

function _curl_parse_cookiefile($file){
    $aCookies = array();
    $aLines = file($file);
    foreach($aLines as $line){
        if('#'==$line{0})
            continue;
        $arr = explode("\t", $line);
        if(isset($arr[5]) && isset($arr[6]))
            $aCookies[$arr[5]] = $arr[6];
        }
    return $aCookies;
}

function GetFriendID( $steam_id ) {
    if ( !$steam_id )
        return 0;
    $auth = explode(':', $steam_id);
    if ( !$auth[2] )
        return 0;
    $fid = $auth[2];
    $fid *=2;
    $fid += 76561197960265728;
    $fid += $auth[1];
    return $fid;
}

$mid = GetFriendID(MY_STEAM_ID);
$fid = GetFriendID($invite_steam_id);

class RSAHelper{
    var $pubkey;
    public function  __construct($modulus, $exponent){
        $res = openssl_pkey_get_public( $this->buildCertificate($modulus, $exponent));
        $details = openssl_pkey_get_details($res);
        $this->pubkey = $details["key"];
    }

    private function buildCertificate($modulus, $exponent){
        $key = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCB" . "iQKBgQCy745x" . $modulus . "ID" . $exponent;
        $key = "-----BEGIN PUBLIC KEY-----\n" . wordwrap($key, 16, "\n", true) . "\n-----END PUBLIC KEY-----";
        return $key;
    }

    public function encrypt($string){
        $crypted = "";
        openssl_public_encrypt($string, $crypted, $this->pubkey);
            return base64_encode($crypted);
        }
    }

    $url="https://steamcommunity.com/login/getrsakey/";
    $PostFields = array(
        'username' => ACC_NAME
    );
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_COOKIESESSION, 1);
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7');
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $PostFields);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__) . '/cookie.txt');
    curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__)."cacert.pem");
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    $result=curl_exec($ch);
    $json=json_decode($result,true);
    $key_mod=$json['publickey_mod'];
    $key_exp=$json['publickey_exp'];
    $timestamp=$json['timestamp'];

    $RSA=new RSAHelper($key_mod,$key_exp);

这是旧脚本的修改版本,应向Steam Group发送邀请.这个版本应该可以使用,但出现错误:

It's a modified version of an old script, which should send invitation to Steam Group. This version should work, but I've got an error:

警告:openssl_pkey_get_details()期望参数1为资源,在第51行的/home/.../public_html/test/steaminv.php中给出的布尔值

Warning: openssl_pkey_get_details() expects parameter 1 to be resource, boolean given in /home/.../public_html/test/steaminv.php on line 51

有人知道此脚本有什么问题吗?

Does anyone know what's wrong with this script?

推荐答案

该错误指出提供的布尔值不是资源.

The error states that a Boolean value was provided not a resource.

这意味着openssl_pkey_get_public函数返回false.

This means the openssl_pkey_get_public function returned false.

只有在提供的字符串不是有效的公共密钥时,才会这样做.

It would only do so if the provided string was not a valid public key.

这是因为类中的buildCertificate方法没有返回有效的PEM格式的公钥.

This is because the buildCertificate method in your class does not return a valid PEM format public key.

几件事:

  1. 使用\r\n而不是\n

使用chunk_split而不是word_wrap

据我所知(如果我错了,请纠正我)您如何构建公用密钥.使用Open SSL构建密钥.

That is not as far as I know (correct me if I am wrong) how you build a public key. Use Open SSL to build the key.

这篇关于openssl_pkey_get_details()期望参数1为资源,给定布尔值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆