PHP rsa 从 pem 文件中获取公钥 [英] PHP rsa get public key from pem file

查看:73
本文介绍了PHP rsa 从 pem 文件中获取公钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从基于 rsa 364 创建的 pem 文件中获取公钥.安装的 crypt(RSA.php) 库仍然低于错误

How can i get publickey from pem file which is created based on rsa 364. installed crypt(RSA.php) library still getting below error

致命错误:调用 C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\rsa.php 中未定义的方法 Crypt_RSA::loadKey()

$file = "C:\key_file.pem"; 
$keypair = Crypt_RSA_KeyPair::fromPEMString(file_get_contents($file));
$public_key = $keypair->getPublicKey(); 
$rsa_pub_key = Crypt_RSA_Key::fromString($public_key->toString()); 
$rsa_obj = new Crypt_RSA; 
$verify_status = $rsa_obj->validateSign($text,$recieved_signed_sign, $rsa_pub_key) ? 'valid' : 'invalid'; 

获取错误为致命错误:调用 C:\Program Files\xxxx\rsa.php 中未定义的方法 PEAR_Error::getPublicKey()

尝试过同样的事情 openssl_verify.验证正在转为 0尝试使用 384 rsa 密钥验证通过 base64_encode 收到的签名.

Tried same thing openssl_verify. verify is rturning 0 Trying to verify sign received with base64_encode with 384 rsa key.

**$base64DecodedStr = base64_decode("A1a0o8JzF7q12Sr4gJvYjslhg5XVA2fWy28.JyohJ05uyiZGyBpqazqb");
$status = openssl_verify($msg,$base64DecodedStr,$pub_key);**

请帮我解决这个问题.非常感谢.

Please help me to resolve this issue. Thanks a lot.

推荐答案

根据 Crypt_RSA 文档,Crypt_RSA 类没有 loadKey() 方法.您将公钥作为关联参数数组的一部分传递给构造函数:

According to the Crypt_RSA documentation, the Crypt_RSA class doesn't have a loadKey() method. You pass the public key to the constructor as part of an associative array of parameters:

$rsa_obj = new Crypt_RSA(array('public_key' => $publickey));

这篇关于PHP rsa 从 pem 文件中获取公钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆