У меня проблема с $ public_key при шифровании RSA, и я получаю пустой результат без ошибок
Я использую phpseclib
Пример:
include('Crypt/RSA.php');
$rsa = new Crypt_RSA();
$plaintext = 'test test';
$public_key = '-----BEGIN CERTIFICATE-----
MIIGQjCCBSqgAwIBAgIQNW5duJ7xtvmwd5qObmTdljANBgkqhkiG9w0BAQUFADB3MQswCQYDVQQG
EwJQTDEiMCAGA1UEChMZVW5pemV0byBUZWNobm9sb2dpZXMgUy5BLjEnMCUGA1UECxMeQ2VydHVt
IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MRswGQYDVQQDExJDZXJ0dW0gTGV2ZWwgSVYgQ0EwHhcN
MTYwNjE1MDU0MTU4WhcNMTkwNjE1MDU0MTU4WjCBvjELMAkGA1UEBhMCUEwxHjAcBgNVBAoMFU1p
bmlzdGVyc3R3byBGaW5hbnNvdzEjMCEGA1UECwwaRGVwYXJ0YW1lbnQgSW5mb3JtYXR5emFjamkx
ETAPBgNVBAcMCFdhcnN6YXdhMRQwEgYDVQQIDAttYXpvd2llY2tpZTEjMCEGA1UEAwwadGVzdC1l
LWRva3VtZW50eS5tZi5nb3YucGwxHDAaBgkqhkiG9w0BCQEWDWpwa0BtZi5nb3YucGwwggEiMA0G
CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC6K/2lXWopQyScTXwXduIfWyk+8ZqrGLhUll1F0J7l
6gfyYx3rLzqAeFIn9tJSS8v1PKj6EQ61lEDZcLcbxsAzK3nYWHhn31Er4/9jrr02jy9TW+DH9jSN
hbeuEO7sEzv3S3wc+/vUSKAW1p5KDcykLD5gfj/79yF68NaG/p+a7rDS0au0Xuj/HMxpRzYa4p+Y
PHoPJRLCVIhcElxB6w29YRJBqjp+bhe3yhWzMzLEozP8HJKEdYRX8OmvvMgKFxDVlxMSogZlZCw2
H7b3Q89dE+Up8EGqXSHSY3N0w3S1WMcWeRI5jcjqcbBBArGPq1DOydn0wh5VqcDtotDGeM/LAgMB
AAGjggKAMIICfDAMBgNVHRM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NOyrRwdy0OuV8f5ahHU9zWH7cEiaMsnn9bIE4clkY/kTm8b2nOsoadH83YV0MrmPKRCleLE1QW
7Ytj9b+exAXLoB5D2NJqiLJD+LX8Y7CGMWGGLOPwonN9stRew5pRVPhY4j8RCLn0Cpuay3rBoOWs
9mzRTV3IiZZFbw==
-----END CERTIFICATE-----';
$rsa->loadKey($public_key);
$rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
echo $ciphertext = $rsa->encrypt($plaintext);
var_dump($rsa->encrypt($plaintext));
, ноесли я поменяю ключ на этот:
$rsa->loadKey('-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4eCZ0
FPqri0cb2JZfXJ/DgYSF6vUpwmJG8wVQZKjeGcjDOL5UlsuusFncCzWBQ7RKNUSesmQRMSGkVb1/
3j+skZ6UtW+5u09lHNsj6tQ51s1SdPrCBkedbNf0Tp0GbMJDyR4e9T04ZZwIDAQAB
-----END PUBLIC KEY-----');
, чем он работает.Что не так с первым ключом?
Спасибо за любую помощь