PHP Classes
elePHPant
Icontem

Error reading public keys

Recommend this page to a friend!

      Top level forums  >  PHP Specialists  >  General  >  Error reading public keys  
Subject:Error reading public keys
Summary:PHP errors reading generated public key files
Messages:3
Author:CloudWindMoonSun
Date:2017-05-16 22:42:25
Update:2017-05-23 09:59:47
 

  1. Error reading public keys   Reply   Report abuse  
CloudWindMoonSun - 2017-05-17 10:33:47
Hi,
I created public key in PHP and exported it to a file. e.g.:

-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA498EWxuZK/KsUgIEusEt
QOJulgTHwb8C4avtzJnzhosTeKooXvyGFPpex6HcQGSRqrWpNr2yhw1BvJvH2UyE
Jisl5BJA5Za+ofmbGifCFwCllZ37U1YpOmqpB2Yt+yYElGh5dp+lqs5Q3u3nPknd
nLS3bxH7qlZBvR9YPWj9x7IuSXJyopAmdJato8xeNHzmBxWD8FgQKICFpLtGsPXq
XRwT0imTs6/EcMqq6fdlp0OyBKyZjw6t47gMeqiuSYz6k41Nf/SbtIC4snUyoUgI
TvnHjWe1cY7js4kY62A9ZpHX0NpG7JXctxVb+aZOv1rS36bUjcP+bug1W3ZKrTG6
hwIDAQAB
-----END PUBLIC KEY-----

On server side (OSX Sierra) I need to read the key file and use it for encryption/decryption using PHP. My PHP code is as following:

$pub_key = file_get_contents("../user_pub_key.crt");
$public_key = openssl_pkey_get_public($pub_key);
var_dump($public_key);
echo openssl_error_string();

Although $public_key is apparently created and var_dump returns the resource number of it, like:

resource(5) of type (OpenSSL key)

but strangely enough, openssl_error_string() also shows the following error:
error:0906D06C:PEM routines:PEM_read_bio:no start line

Does it mean that OpenSSL and PHP on my Mac are not compatible. Any suggestion for resolving this problem please?

Thanks,
Hassan&

There are 2 replies in this thread, which are not being displayed.
Browsing this forum thread replies is available only to premium subscribers.


Go to the premium subscriptions page to learn how to become a premium subscriber and have full access to this forum.