I have this RSA public key:
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtixUGzGpLXgZ7AV1HfmIHV/FEF+fww77FekRc2oLhUOd4HitwCPo76fjtdsQBEt8w9HZ3CXVphaAU2BA6MEZJ3ShVMsdAXb2ZA1C+lu7k1GV9M/BhucTg35HujSK647Sc5MwVLwFsN80dAnGsZF8gwb2TNUzXHwzbAb30T01zuqf8RCM75OwKZFYqzu7FOVrtk/w9mh92MOXG0l7WSqNIctu8Kxka/tEJJIA5nqMGNMocjwprXy66NS7FFy1GY+NnxfFLtODqq0tllc50UCDsnqSvNmj2wcnAcsCzNOoxPPgp7t8S+sQvOzgc5W3CDjIsYEiGD+vzSVNkGiRou577wIDAQAB
(Every other key I try gives the same error, too)
and this string:
$str = "VOTE\n" .
"server-list\n" .
"$user\n" .
"$userip\n" .
time()."\n";
I use this code to make the string become exactly 256 bytes so that it follows the standard for this specific application:
$leftover = (256 - strlen($str)) / 2;
while ($leftover > 0) {
$str .= "\x0";
$leftover--;
}
To format the key, I do this:
$key = wordwrap($key, 65, "\n", true);
$key = <<<EOF
-----BEGIN PUBLIC KEY-----
$key
-----END PUBLIC KEY-----
EOF;
When I do openssl_public_encrypt($str, $encrypted, $key);
I get the following warning:
Warning: openssl_public_encrypt() function.openssl-public-encrypt: key parameter is not a valid public key in ...
I'm not sure why this is happening. This is what the key looks like when I echo it:
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtixUGzGpLXgZ7AV1HfmIH
V/FEF
fww77FekRc2oLhUOd4HitwCPo76fjtdsQBEt8w9HZ3CXVphaAU2BA6MEZJ3ShVMsd
AXb2ZA1C
lu7k1GV9M/BhucTg35HujSK647Sc5MwVLwFsN80dAnGsZF8gwb2TNUzXHwzbAb30T
01zuqf8RCM75OwKZFYqzu7FOVrtk/w9mh92MOXG0l7WSqNIctu8Kxka/tEJJIA5nq
MGNMocjwprXy66NS7FFy1GY
NnxfFLtODqq0tllc50UCDsnqSvNmj2wcnAcsCzNOoxPPgp7t8S
sQvOzgc5W3CDjIsYEiGD vzSVNkGiRou577wIDAQAB
-----END PUBLIC KEY-----
Any help would be appreciated!
Edit: A working key should look like this:
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmHzD76i8DA25nC+Qsswi
OM0lW+gViiQD4tEm7suxBc2BGibtdlrsprVIId92hSjQKx4x8+XVWU6k89T5vy8Y
txpXN759OWdGkDi8uvZuYclMjW9Rao+oqSvbXH37R7oSY287I+6uOHclGhniQN3q
RyoXBkbhDk0/FTI/i549q/gGk1UZYv449KLrDOqmtohRcIyAYVnvvWtD1kIzourq
hMtEIrPqwoBqTaUA9kOIXw1jMovao2TN52j48KgOg9KjqtdwUwD9e6n7hJd/subF
6woc8L7zjJFOHH5gacUC7vtiMpBpnSyLQpjFLepYYwftjsRmg4xLdh+Zvgw3xqi4
lwIDAQAB
-----END PUBLIC KEY-----
+
signs in your key? They're gone in the formatted block. – ReynoldA-Ba-b0-9
and/
&+
to encode bytes, and possibly the=
character for padding the last part. – Lattawordwrap
function, it seems aimed at splitting strings on word boundaries. You are better off just counting characters and inserting the newline characters (both of them if I'm not mistaken) manually. – Latta