phpseclib不适用于来自终端的php5-cli [英] phpseclib not works with php5-cli from terminal
问题描述
我在raspbian(debian操作系统)上安装了php5-cli软件包,并下载了 phpseclib 在/ cli /目录中。
我通过以下方式创建了一个测试文件,以使用公共密钥(在我具有相同库的apache服务器中生成)对文本进行加密:
I installed php5-cli package on my raspbian (debian OS) and I downloaded phpseclib in /cli/ directory. I created a test file to encrypt text with a public key (generated within my apache server on which I have the same library) in this way:
include('libs/Crypt/RSA.php');
$rsa = new Crypt_RSA();
$rsa->loadKey($myPublicKey);
$encrypted = $rsa->encrypt("my text");
echo "result: " .$encrypted;
如果我尝试输入 php test.php ,则结果
变量为空。为什么?这是由于我使用php5-cli而不是php5从终端e执行文件吗?
如何获得此加密操作的结果?
谢谢。
If I try to type php test.php the result
variable is empty. Why? It's due to the fact I execute the file from terminal e with php5-cli instead of php5 ?
How Can I obtain the result of this encrypting operation?
Thanks.
推荐答案
您提供的源代码正确。如果 $ encrypted
的值为空,则可能是由于 loadKey
中提供的密钥不正确。
The source code you have provided is correct. If the value of $encrypted
is empty, it's possible due to an incorrect key supplied in loadKey
.
根据文件 RSA.php
中的注释,该命令将返回 false
如果密钥无效:
According to the comments in the file RSA.php
, then the command will return false
if the key is invalid:
/**
* Loads a public or private key
*
* Returns true on success and false on failure (ie. an incorrect password was provided or the key was malformed)
*
* @access public
* @param String $key
* @param Integer $type optional
*/
function loadKey($key, $type = false){
...
}
这篇关于phpseclib不适用于来自终端的php5-cli的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!