代码使用:
$privkey=<<<PK
-----BEGIN RSA PRIVATE KEY-----
MIICWgIBAAKBgQDI12iJMtuVD2W6y9EtwlZe335CKdQTjq9kDxmfo0deTXcBvSK7
ZgUq1bCmKaSeYP7VFQHUN0x79g+CvxHY0shWtCUElc2zE07hZlLiJyY4STUcBzA4
oAR7J19hZFdfLpb9inW5lrQ7r3wBpX1QqKpHHvAKONM6WyLTsNRo4CaT0wIBIwKB
gGdKNcLm9JXNZ4SjVaKBM7vDZYEc03fFuUlm2fpT+NFpqurzjjR9nEHqPZdInc3L
e74Kzb2YyD/AX7+VduSJqNs4orVM48P8ElpSyr56RvngJ6rtrt0m4r7Mcgcsus9G
NIZgTetviRWReJKIiGEbIT7ryoCNw8F8w7dgM6SJ+MYLAkEA7eCao3RMQJbpXCuR
p/V6XtuWTy1RjArwET3mUCz0tZUOJvt1D9Dx2NstR37SMwlEk3EEnQmswL/Zp9LZ
PSlw4QJBANgkezIsvxM+8xPV+pFt2AvTgHgScfMHwsF8pgRNZali6hn/M5/Kg3So
KTgRwaRulmuuKBZbI5mRFXidJQh89zMCQQCcUcS0jkC8uvEfT9S+1IOda7qLzVLY
XvWHrFWFJNtSwQlM0SEKZLwva3WGwQ3JxEMBze0WvTcCUi/x8PUoMSzrAkB1VaH2
qpOcu8XI8IC1WOL/Gws53iCZ36Q9JmjAgcl5NbJIoHscOrxj5kJDAlMtYJrMvaC7
rdF/QCGZP10/H0RdAkB8q1PPumOoL7vprMDVGhRdAQ7xG25yj8EmJd9hsWGGqXYk
YrJJGQ5oam6K0o9OPNgIITW9kOunxqmkW7KodKhL
-----END RSA PRIVATE KEY-----
PK;
require_once('Crypt/RSA.php');
$rsa=new Crypt_RSA();
$key=Crypt_RSA_Key::fromString($privKey);
echo "key: ".$key->toString()."\n";
$str=$rsa->encrypt("hello world",$key);
echo "$str\n";
当我运行它时,我收到此错误:
[27-Apr-2012 17:38:17] PHP Fatal error: Call to undefined method PEAR_Error::bin2int() in /usr/share/pear/Crypt/RSA.php on line 364
为什么这不起作用的任何想法?我确认这些文件存在:
RSA/Math/GMP.php
RSA/Math/BCMath.php
RSA/Math/BigInt.php
应该是RSA类使用的数学包装器。
答案 0 :(得分:1)
PEAR的Crypt_RSA被phpseclib's Crypt_RSA取代,依此:
http://pear.php.net/package/Crypt_RSA
原因是phpseclib的实现免受PEAR实施所带来的漏洞的影响:
http://www.securityfocus.com/archive/1/520683
因此,我建议只使用phpseclib的Crypt_RSA。