我试图加密一些东西,phpseclib
但由于某种原因,该encrypt()
函数不返回任何东西。
这是我现在拥有的核心:
include('/pathto/Crypt/RSA.php');
$key = '-----BEGIN PUBLIC KEY-----
MIIB/TCCAWYCCQDJ7TMYJFzqYDANBgkqhkiG9w0BAQUFADBCMQswCQYDVQQGEwJjbjEVMBMGA1UE
BwwMRGVmYXVsdCBDaXR5MRwwGgYDVQQKDBNEZWZhdWx0IENvbXBhbnkgTHRkMCAXDTE3MDUwOTA1
MTkxMFoYDzIxMTcwNDE1MDUxOTEwWjBCMQswCQYDVQQGEwJjbjEVMBMGA1UEBwwMRGVmYXVsdCBD
aXR5MRwwGgYDVQQKDBNEZWZhdWx0IENvbXBhbnkgTHRkMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCB
iQKBgQDb8V0OYUGP3Fs63E1gJzJh+7iqeymjFUKJUqSD60nhWReZ+Fg3tZvKKqgNcgl7EGXp1yNi
fJKUNC/SedFG1IJRh5hBeDMGq0m0RQYDpf9l0umqYURpJ5fmfvH/gjfHe3Eg/NTLm7QEa0a0Il2t
3Cyu5jcR4zyK6QEPn1hdIGXB5QIDAQABMA0GCSqGSIb3DQEBBQUAA4GBANhIMT0+IyJa9SU8AEya
WZZmT2KEYrjakuadOvlkn3vFdhpvNpnnXiL+cyWy2oU1Q9MAdCTiOPfXmAQt8zIvP2JC8j6yRTcx
JCvBwORDyv/uBtXFxBPEC6MDfzU2gKAaHeeJUWrzRv34qFSaYkYta8canK+PSInylQTjJK9VqmjQ
-----END PUBLIC KEY-----';
$rsa = new Crypt_RSA();
$rsa->loadKey($key);
$sometext = 'test this text';
echo $rsa->encrypt($sometext);
我下载了1.0版本。
怎么了?
我挖得更深一点,发现了这个问题,并将我的部分测试代码更改为:
if (!$rsa->encrypt($sometext)) {
echo "false";
} else {
echo $rsa->encrypt($sometext);
}
这证明我的密钥在某种程度上是错误的。但是格式应该是怎样的呢?