我使用的代码:
$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 类使用的数学包装器。