简体   繁体   中英

`openssl_pkey_get_details` only returning `bits`, `key` and `type` values (can't access [rsa])

I'm trying to work with a useful JavaScript library, JSBN, as outlined in this post .

Basically, I want to set up a system where I encrypt using this library (on the client side) with a public key, and then decrypt on the server side using PHP and a private key.

I have one main problem at the moment: After implementing and trying out the exact same code used in the examples I've seen, the essential openssl_pkey_get_details function is returning strange results. I use RSA, 4096 bit, 'sha512' for my public key, and I've also used the varying types of keys I've seen others use in their examples.

This is the type of output openssl_pkey_get_details produces, when ran on my JustHost server:

Array
(
    [bits] => 4096
    [key] => -----BEGIN PUBLIC KEY-----
        MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEArLEG2TvFVWV7b5N3ICvN
        tdW8/rF8P2lOLpWuA+yPlia1XVoohKl/UIkCrJUF6aS1d1KPbUa00uskWuH6TGSi
        +A4B3/PWO9MGH2CklHnjeblYF7shGz6zwGK7wtQxpN67j3nOKBvegRolk6FCidTt
        JcFB4+DEfn/avwL6PxLRJYvMoUgHqCQCwh6frIUiwzYttpHB0aOQaSpc4/vXKElq
        C4FAmEGfmhlofHB3b3bnz+fYKyzbCkek51NqMFK4e7Gvek3uSKyzXKKD6LQQcXyT
        /lxvvXWTb3qkoRzZNdrsAVbmIRLBQfYvHkcFQolh/D7WAVd59S+/vhsf+rDfq42O
        Sh4J1ph7dBpcyhzIoNoioCh3SU9fd1mwNG51PFU3AmFUmWPMeuYI47g7Sx+amc0R
        nITC60E4hdvr2H8OO0FGk0nxlVPulVwWT7OfcV4xFU2wLdKawq+ErQwkQWTMh+V+
        rRDKBiFjQPbgRop7EzYlEA6H92KfI/g7mNMVDoUFd6HBF9Hdr2yF1A8N0nfmoHJ7
        q0FDJS/0ZYTnF7r82EBU6PuX1y0r2T9gGh6WQf8c1FvprvPQMz9/UXuyPDJqRfRq
        pWopF53l60yrrpG7LZpo2NyL1TaVeOLlB8rwSeYrPQn6WBpzIf7FxThJPKMqy8EP
        OaJ5DkVyRGP6tqhH75hlHCUCAwEAAQ==
        -----END PUBLIC KEY-----

    [type] => 0
)

Notice, the type is returned as 0 ; this should mean that the type is indeed an RSA key. According to php.net , it should be the case: Above type , there should be another element rsa , holding the likes of the n and e values. These values are needed to create an RSAKey object with JSBN, and I cannot access them.

Here is some of my source code:

$config = array(
    "digest_alg" => , 'sha512'
    "private_key_bits" => 4096,
    "private_key_type" => OPENSSL_KEYTYPE_RSA
);
// Create the private and public key
$resource = openssl_pkey_new($config);
// Place the private key into $pk
openssl_pkey_export($resource, $pk);
$kh = openssl_pkey_get_private($pk);
$details = openssl_pkey_get_details($kh);
print_r($details);

Same issue with php 5.2.17 (in CLI: php -v), OS Linux, OpenSSL 1.0.1e-fips 11 Feb 2013.

@ php 5.3.14 all works fine and exist $details['rsa']: OS Windows, OpenSSL 1.0.1g 7 Apr 2014, also works @ PHP 5.3.3, OS Linux, OpenSSL 1.0.1f 6 Jan 2014.

So, maybe problem connected with openssl version

openssl version

lower than 1.0.1f 6 Jan 2014 or PHP version

php -v

lower than 5.3.

UPD: don't returns ['rsa'] @ php 5.2.17 with OS Linux and OpenSSL 1.0.1f 6 Jan 2014.

So, my conclusion about that your server running under PHP < 5.3.0.

Is it correct?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM