gpt4 book ai didi

PHP openssl_public_encrypt "key parameter is not a valid key"

转载 作者:可可西里 更新时间:2023-11-01 12:54:34 26 4
gpt4 key购买 nike

我有这个 RSA 公钥:

MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtixUGzGpLXgZ7AV1HfmIHV/FEF+fww77FekRc2oLhUOd4HitwCPo76fjtdsQBEt8w9HZ3CXVphaAU2BA6MEZJ3ShVMsdAXb2ZA1C+lu7k1GV9M/BhucTg35HujSK647Sc5MwVLwFsN80dAnGsZF8gwb2TNUzXHwzbAb30T01zuqf8RCM75OwKZFYqzu7FOVrtk/w9mh92MOXG0l7WSqNIctu8Kxka/tEJJIA5nqMGNMocjwprXy66NS7FFy1GY+NnxfFLtODqq0tllc50UCDsnqSvNmj2wcnAcsCzNOoxPPgp7t8S+sQvOzgc5W3CDjIsYEiGD+vzSVNkGiRou577wIDAQAB

(我尝试的所有其他键也都出现相同的错误)

和这个字符串:

$str = "VOTE\n" .
"server-list\n" .
"$user\n" .
"$userip\n" .
time()."\n";

我使用此代码使字符串正好变成 256 字节,以便它符合此特定应用程序的标准:

$leftover = (256 - strlen($str)) / 2;
while ($leftover > 0) {
$str .= "\x0";
$leftover--;
}

为了格式化 key ,我这样做了:

    $key = wordwrap($key, 65, "\n", true);
$key = <<<EOF
-----BEGIN PUBLIC KEY-----
$key
-----END PUBLIC KEY-----
EOF;

当我执行 openssl_public_encrypt($str, $encrypted, $key); 时,我收到以下警告:

警告:openssl_public_encrypt() function.openssl-public-encrypt: key parameter is not a valid public key in ...

我不确定为什么会这样。这是我回显时 key 的样子:

-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtixUGzGpLXgZ7AV1HfmIH
V/FEF
fww77FekRc2oLhUOd4HitwCPo76fjtdsQBEt8w9HZ3CXVphaAU2BA6MEZJ3ShVMsd
AXb2ZA1C
lu7k1GV9M/BhucTg35HujSK647Sc5MwVLwFsN80dAnGsZF8gwb2TNUzXHwzbAb30T
01zuqf8RCM75OwKZFYqzu7FOVrtk/w9mh92MOXG0l7WSqNIctu8Kxka/tEJJIA5nq
MGNMocjwprXy66NS7FFy1GY
NnxfFLtODqq0tllc50UCDsnqSvNmj2wcnAcsCzNOoxPPgp7t8S
sQvOzgc5W3CDjIsYEiGD vzSVNkGiRou577wIDAQAB
-----END PUBLIC KEY-----

如有任何帮助,我们将不胜感激!

编辑:工作 key 应如下所示:

-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmHzD76i8DA25nC+Qsswi
OM0lW+gViiQD4tEm7suxBc2BGibtdlrsprVIId92hSjQKx4x8+XVWU6k89T5vy8Y
txpXN759OWdGkDi8uvZuYclMjW9Rao+oqSvbXH37R7oSY287I+6uOHclGhniQN3q
RyoXBkbhDk0/FTI/i549q/gGk1UZYv449KLrDOqmtohRcIyAYVnvvWtD1kIzourq
hMtEIrPqwoBqTaUA9kOIXw1jMovao2TN52j48KgOg9KjqtdwUwD9e6n7hJd/subF
6woc8L7zjJFOHH5gacUC7vtiMpBpnSyLQpjFLepYYwftjsRmg4xLdh+Zvgw3xqi4
lwIDAQAB
-----END PUBLIC KEY-----

最佳答案

我突然想到为什么它不起作用,所以我来这里是为了回答我自己的问题。现在我想起来了,它与@sarnold 最初所说的有关:+ 号消失了(它们被空格代替)

事实证明,因为我是通过 HTTP POST 获取 key 的,所以它格式化了 URL(以及 key ),将所有 + 号都变成了空格。那丢掉了 key 并引起了这个难题。

感谢您的帮助。 :)

关于PHP openssl_public_encrypt "key parameter is not a valid key",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9881696/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com