我编写了一个简单的测试,但它发送给我:“未经验证”,我猜是因为我使用的是整个证书而不是公钥。什么方法给我公钥?
$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';
答案 0 :(得分:1)
对不起你的验证,试试这个
$rsa->loadKey($rsa->getPublicKey());
echo $rsa->verify($plaintext, $signature) ? 'Verified' : 'Unverified';