Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php openssl_pkey_get_details()期望参数1是给定的资源_Php_Openssl_Rsa_Steam - Fatal编程技术网

Php openssl_pkey_get_details()期望参数1是给定的资源

Php openssl_pkey_get_details()期望参数1是给定的资源,php,openssl,rsa,steam,Php,Openssl,Rsa,Steam,我在“某处”找到了这个脚本: 这是一个旧脚本的修改版本,应该向Steam组发送邀请。此版本应该可以工作,但我有一个错误: 警告:openssl_pkey_get_details()希望参数1是第51行的/home/../public_html/test/steaminv.php中给出的资源布尔值 有人知道这个脚本有什么问题吗?错误表明提供的布尔值不是资源 这意味着openssl\u pkey\u get\u public函数返回false 只有当提供的字符串不是有效的公钥时,才会这样做 这是因为

我在“某处”找到了这个脚本:

这是一个旧脚本的修改版本,应该向Steam组发送邀请。此版本应该可以工作,但我有一个错误:

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


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

错误表明提供的布尔值不是资源

这意味着
openssl\u pkey\u get\u public
函数返回false

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

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

有几件事:

  • 使用
    \r\n
    而不是
    \n

  • 使用
    chunk\u split
    not
    word\u wrap

  • 这不是我所知道的(如果我错了,请纠正我)如何构建公钥。使用开放SSL构建密钥

  • 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);