简体   繁体   中英

how to get public key with Crypt_RSA

I have coded a simple test, but it sent me: "Unverified", I guess because I am using the whole certificate instead of the public key. What method gives me public key?

$rsa = new Crypt_RSA();
$rsa->setPassword('here I include password');
$rsa->loadKey(file_get_contents('i.pem')); // private key
$plaintext = 'abc';
$rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
$signature = $rsa->sign($plaintext);
//now the verification
$rsa->loadKey(file_get_contents('instancia_ope.crt')); //here maybe WRONG
echo $rsa->verify($plaintext, $signature) ? 'Verified' : 'Unverified';

Ah sorry your verifying, try this

$rsa->loadKey($rsa->getPublicKey()); 
echo $rsa->verify($plaintext, $signature) ? 'Verified' : 'Unverified';

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