1

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';
neubert
  • 15,947
  • 24
  • 120
  • 212
user1873420
  • 101
  • 1
  • 2
  • 7
  • the line //here maybe WRONG, indicates the public key file – user1873420 Feb 20 '13 at 23:33
  • PLease mention packages: http://stackoverflow.com/questions/14991887/how-to-get-public-key-with-crypt – SteAp Feb 20 '13 at 23:37
  • SteAP, you mean in the subject line? or where, and what package? – user1873420 Feb 20 '13 at 23:47
  • @SteAp is a pear package. If you don't know what it is google it and you probably shouldn't be answering. – shapeshifter Feb 21 '13 at 00:33
  • 1
    I'm aware of this fact. Nevertheless, I propose to always include references - since this would assist people who'd like to answer. No longer maintained PEAR package http://pear.php.net/package/Crypt_RSA migrated to phpseclib http://phpseclib.sourceforge.net – SteAp Feb 21 '13 at 22:09

1 Answers1

1

Ah sorry your verifying, try this

$rsa->loadKey($rsa->getPublicKey()); 
echo $rsa->verify($plaintext, $signature) ? 'Verified' : 'Unverified';
shapeshifter
  • 2,967
  • 2
  • 25
  • 39