开发者

PHP rsa gePublicKey from .pem file [duplicate]

This question already has answers here: Closed 12 years ago.

Possible Duplicate:

PHP rsa get public key from pem file

Trying to verify received signature with following code.

$file = "C:\key_file.pem";  
$keypair = Crypt_RSA_KeyPair::fromPEMString(file_get_contents($file)); 
$public_key = $keypair->getPublicKey(); 
$rsa_pub_key = Crypt_RSA_Key::fromString($public_key->toString()); 
$rsa_obj = new Crypt_RSA; 
$verify_status =  $rsa_obj->validateSign($text,$recieved_signed_sign, $rsa_pub_key) ? 'valid' : 'invalid';
开发者_StackOverflow社区

getting error as Fatal error: Call to undefined method PEAR_Error::getPublicKey() in C:\Program Files\xxxx\rsa.php


It looks like you just dont have installed the pear package Crypt_RSA

To do so you have to install php-pear and then install the package using it.

On debian basted systems this is usually just a matter of doing

sudo apt-get install php-pear

sudo pear i Crypt_RSA

on windows i cant tell you but i am sure you can quickly find howto guides on google.

i also think then functions you use require a rather fresh release, so you may have to upgrade pear and update the plugin using the -f switch


My recommendation: don't use PEAR's Crypt_RSA but rather phpseclib's Crypt_RSA.

PEAR's Crypt_RSA isn't PKCS#1 compliant, meaning signatures or ciphertexst's generated with it are not going to be interoperable with other languages, it doesn't support passworded private keys, and hasn't been actively maintained for years.

More info on phpseclib:

http://phpseclib.sourceforge.net/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜