欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

openssl_get_publickey() 的运行结果在php7和php5.6上不一样????

程序员文章站 2022-03-26 13:17:58
...
hi everyone,

today i meet a strange problem while the function openssl_get_publickey() runs well in php 7 while report an error in php5. 6.16 and php5.5.12

here is the test code:
<?php

//define a pem formatted string varaible named $key
$key = <<<EOF
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCnxj/9qwVfgoUh/y2W89L6BkRAFljhNhgPdyPuBV64bfQNN1PjbCzkIM6qRdKBoLPXmKKMiFYnkd6rAoprih3/PrQEB/VsW8OoM8fxn67UDYuyBTqA23MML9q1+ilIZwBC2AQ2UBVOrFXfFl75p6/B5KsiNG9zpgmLCUYuLkxpLQIDAQAB
-----END PUBLIC KEY-----
EOF;

//get the public key
$res = openssl_get_publickey($key);
var_dump($res);

?>

while in php7.0.0 the result is normal and correct here is the output
{

D:\wamp64\www\php\index.php(50) : eval()'d code:24:resource(4, OpenSSL key)

}

but not the same result in php 5.6.16 and php 5.5.12 here is the output
{

D:\wamp64\www\php\index.php(50) : eval()'d code:24:boolean false

}

so can you help me with the problem???

回复内容:

hi everyone,

today i meet a strange problem while the function openssl_get_publickey() runs well in php 7 while report an error in php5. 6.16 and php5.5.12

here is the test code:
<?php

//define a pem formatted string varaible named $key
$key = <<<EOF
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCnxj/9qwVfgoUh/y2W89L6BkRAFljhNhgPdyPuBV64bfQNN1PjbCzkIM6qRdKBoLPXmKKMiFYnkd6rAoprih3/PrQEB/VsW8OoM8fxn67UDYuyBTqA23MML9q1+ilIZwBC2AQ2UBVOrFXfFl75p6/B5KsiNG9zpgmLCUYuLkxpLQIDAQAB
-----END PUBLIC KEY-----
EOF;

//get the public key
$res = openssl_get_publickey($key);
var_dump($res);

?>

while in php7.0.0 the result is normal and correct here is the output
{

D:\wamp64\www\php\index.php(50) : eval()'d code:24:resource(4, OpenSSL key)

}

but not the same result in php 5.6.16 and php 5.5.12 here is the output
{

D:\wamp64\www\php\index.php(50) : eval()'d code:24:boolean false

}

so can you help me with the problem???

相关标签: php