簡體   English   中英

如何使用Crypt_RSA獲取公鑰

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM