我已经下载了phpseclib0.3.9.zip。当我运行此代码时,会出现以下错误。我不知道是什么原因。
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . 'E:/software/PHPRSA');
include 'Crypt/RSA.php';
$rsa = new Crypt_RSA();
extract($rsa->createKey());
$plaintext = 'terrafrost';
$rsa->loadKey($privatekey);
$ciphertext = $rsa->encrypt($plaintext);
$rsa->loadKey($publickey);
echo $rsa->decrypt($ciphertext);
?>
以下是错误报告:
Call Stack
# Time Memory Function Location
1 0.0020 131696 {main}( ) ..'test1.php:0
2 0.0290 1276184 Crypt_RSA->createKey( ???, ???, ??? ) ..'test1.php:7
3 27.4046 1356352 Math_BigInteger->randomPrime( object(Math_BigInteger)[8], object(Math_BigInteger)[10], bool ) ..'RSA.php:662
帮助被欣赏。
超时了。
生成 RSA 密钥对是一项极其耗时的操作。特别是,当它生成两个素数时,它会创建一大堆随机数并测试每个素数,直到找到一个素数。
拥有bcmath或gmp甚至openssl将大大加快速度。
您可以做一些其他事情来加快速度......
-
define('CRYPT_RSA_SMALLEST_PRIME', 256)
可以提供帮助。这将使phpseclib使用多素数RSA。每个密钥将是 256 位而不是 512 位,因此生成质数会更快。另一方面,您的密钥可能不会与其他 RSA 实现进行很好的互操作。 -
您可以使用超时参数和 AJAX 来使其花费多长时间。更多信息: http://phpseclib.sourceforge.net/rsa/examples.html#timeout