[英]how to get public key with Crypt_RSA
我已經編寫了一個簡單的測試代碼,但是它發送給我:“未驗證”,我想是因為我使用的是整個證書而不是公鑰。 什么方法給我公開密鑰?
$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';
不好意思,請嘗試這個
$rsa->loadKey($rsa->getPublicKey());
echo $rsa->verify($plaintext, $signature) ? 'Verified' : 'Unverified';
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.