#php #gnupg #openpgp
#php #gnupg #openpgp
Вопрос:
Смотрите Исходный код ниже, чтобы воспроизвести эту проблему. Шаг 1 шифрует сообщение с помощью gnupg, а шаг 2 расшифровывает сообщение с шага 1 с помощью openpgp-php. Для выполнения кода убедитесь, что у вас установлены PHP gnupg и openpgp-php. документацию openpgp-php см. в singpolyma / openpgp-php.
Чего я пытаюсь достичь, у меня есть внутренний сервер и мобильное приложение, которое может обмениваться данными только по электронной почте. Для простоты предположим, что шаг 1 — это внутренний сервер, а шаг 2 — мобильный клиент. Сообщения передаются между сервером и клиентом. Серверный сервер должен иметь возможность зашифровать сообщение, предназначенное для мобильного приложения, которое, в свою очередь, расшифровывает сообщение и отправляет зашифрованный ответ на серверную часть.
<?php
@include_once dirname(__FILE__).'/vendor/autoload.php';
require_once dirname(__FILE__).'/lib/openpgp.php';
require_once dirname(__FILE__).'/lib/openpgp_crypt_rsa.php';
require_once dirname(__FILE__).'/lib/openpgp_crypt_symmetric.php';
/**
* Note: Step 1 and step 2 represents a client-server setup
* I know it's wrong to share private keys but this was generated specifically for this test
*/
/**
* step #1 (Encryption)
* encrypt message meant for hamfri-2@example.com at step #2
*/
// public key for hamfri-2@example.com
$public_key1 = "-----BEGIN PGP PUBLIC KEY BLOCK-----
mQENBF xv34BCAD9ttzdbXx81yKIlWi0zqRgHVYc07M9ymoqCzoIIrmaCcvkARAJ
I4IZ36PnXxnLdfMehMDjxeT6PAJDb71oMc85jA h5c ya4b m9OwlGW/e7WgieBB
WGt8NRnnKjwGbwDq7qd2aC2T/ZDBZQFF4wAJjoZop5Wh7NxK8QFV05ES6KXU/hJF
wySbyoSYJb4A3VNrpoEF92vA22aUFn2RrktCXwaaMXoOyLuFDebxOrKgzI5EfhMa
CRBxv4ufNfcAm1uEpqILngou/kxUs5QYW6VaSmV858 bpzcMGR73X1hHY9p0dHO1
QTaIJU/8E91whaCxihDOsyO5jJG6DIhEbwJVABEBAAG0IFBST0ZJR0FURSA8aGFt
ZnJpLTJAZXhh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hOT5CwmjJ
LzmQwhWzpAlhw93sQTJY7oKyW3lasxyDjBhIDHz0lagNfU6S5ZkR8U5S2qoM6VRr
bDVP224HXXjhLUvbChF G5MvWaAOExPvz2Sc69jcQaQ5D4PM65qfatoJZEdQjREn
YGU4c7ZqPPunQSbIlMzufFsu2mMM1/mLKMA12 VPoMbrzoMoJD4ENNsFjXmYjlDl
wLrs1pYDu7bjm5Aqz1iylMrup eiv5TqXFX93PR50 UH/A0gg6LkuBJOJ9G1TCN/
G32NmB3/NOhLPZgdF9E36cxV6/EiOwYP2YVG4eBS Sajk4PieYupNI91rwU5O9gR
UCekv3TbI7F41oin/tF9 RoLpGyRjOT4P7PsBfg9PTIzHBlVmIBo88JP14IhRcN
najX81Mw01esspl2 bkX1MgmZ7SPoODZ422BLYEt8qQrxLoOI6gUzz/NpY4OpoRS
Qdx3TEmHKzLIIWZgkMC1IwNX4Jc4gLF8pMD4miSwm5RRlHzop7APmCs6F7jC evo
H3xWQTvkq7Rrh0ykvZOeX kEvEfglFrFDM2GE0XVy khDenC6BHgx2D6ZJIPOs18
pko=
=vTCt
-----END PGP PUBLIC KEY BLOCK-----
";
// private key for hamfri@example.com
$private_key1 = "-----BEGIN PGP PRIVATE KEY BLOCK-----
lQOXBF xvukBCADfsgmVrgw95kpxL yM0BRC4Z/UHRoOCj4N9lOyvhUoa9rs30/W
Xd8RXddkF2pjPr2OjRRe PbpKxkkxAe1qxmICaIh/Xp/gS6XHGdqgvX/PuQhw3 T
eGSVdXLxSwRdlGW1AZeH3WWSmqviYEtkwxWoah6g4ubmd/b6wp3EtSw4YpA3l1 C
J313MV1IbptjJkrLHy JqAV4CA6ziCkOwERc5fvtNdmmvbXrMfb5ObN2F6RfYwZS
yLSvJB7n4CDsvLwGbXRHP0we0 eXJLt902k0uTW27IZhHElatvnxXwjqA5mcVfIK
W3ks3VHLx0PbjIhghAUg7Pg8HgPlPGVBS8mhABEBAAEAB/df5jO1t6gH4XKIk8MV
mx8UjSW4CcHhwwJ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3dnVU4oPSLdC2reQW
FALtFgSkf6YGF0bbZOFdk41/6NS6mB5/5ao11bICKvQlOXB9JihiSJOteKmAx8wv
TXYRnrUxH039PaOpdAdzMf4OAFw1Hsd5qR4 ZDdAzeRlGitKPg YxQ48iHDfFPrW
hVub9BQ=
= jZf
-----END PGP PRIVATE KEY BLOCK-----
";
$message = "Testing again and again";
$gpg = new gnupg();
$publicKey = $gpg->import($public_key1);
$fingerprint = $publicKey['fingerprint'];
// catch errors
$gpg->seterrormode(gnupg::ERROR_EXCEPTION);
// enable armored output
$gpg->setarmor(1);
$gpg -> setsignmode(gnupg::SIG_MODE_DETACH);
// encrypt plain text
try{
$gpg->addencryptKey($fingerprint);
$cipher_text = $gpg->encrypt($plain_text);
echo "n". $cipher_text ."n";
}
catch(Exception $e){
die('Error '.$e->getMessage());
}
/**
* step #2 (Decryption)
* decrypt message from hamfri@example.com in step 1
*/
//public key for hamfri@example.com
$publickey2 = "-----BEGIN PGP PUBLIC KEY BLOCK-----
mQENBF xvukBCADfsgmVrgw95kpxL yM0BRC4Z/UHRoOCj4N9lOyvhUoa9rs30/W
Xd8RXddkF2pjPr2OjRRe PbpKxkkxAe1qxmICaIh/Xp/gS6XHGdqgvX/PuQhw3 T
eGSVdXLxSwRdlGW1AZeH3WWSmqviYEtkwxWoah6g4ubmd/b6wp3EtSw4YpA3l1 C
J313MV1IbptjJkrLHy JqAV4CA6ziCkOwERc5fvtNdmmvbXrMfb5ObN2F6RfYwZS
yLSvJB7n4CDsvLwGbXRHP0we0 eXJLt902k0uTW27IZhHElatvnxXwjqA5mcVfIK
W3ks3VHLx0PbjIhghAUg7Pg8HgPlPGVBS8mhABEBAAG0HlBST0ZJR0FURSA8aGFt
ZnJpQGV4YW1wbGUuY29tPokBTgQTAQoAOBYhBEPLdrBteggCLZn/FUBJzWsd7w7z
BQJfsb7pAhsvBQsJCAcCBhUKCQgLAgQWAgMBAh4BAheAAAoJEEBJzWsd7w7zJ6sI
AIa7iqAWRIS/Ko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85j0
1796VJ2sPK5 JDdtP6tpS/IoMZL49vqzQwfhxCXcl7DItKhBf1tZC8CgpTvdbCZo
PtIeTChS9iBwA1Q5KQQI9/HmvCxTUWfjQjM294D3CADEurGol Qwv hkq4xW6lmP
ULLTxwxVt/tQWFfhbNFtlLrWdL5gMzfCzu5ilVzWpXpijPNqLEQsBV0mpbqF aOh
nKktPAxgSTmhYlsUOXEkgRGDXqtvxLKuno1uGyJVlGEZkMev9XUk9r4Md0x IGza
VZK8DR4o6lM7iK qg55Pq3mKzaque1j7kSfOgRLVt3Z1VOKD0i3Qtq3kFhQC7RYE
pH mBhdG22ThXZONf jUupgef WqNdWyAir0JTlwfSYoYkiTrXipgMfML012EZ61
MR9N/T2jqXQHczH DgBcNR7HeakePmQ3QM3kZRorSj4PmMUOPIhw3xT61oVbm/QU
=9rM9
-----END PGP PUBLIC KEY BLOCK-----
";
//private key for hamfri-2@example.com
$privateKey2 = "-----BEGIN PGP PRIVATE KEY BLOCK-----
lQOYBF xv34BCAD9ttzdbXx81yKIlWi0zqRgHVYc07M9ymoqCzoIIrmaCcvkARAJ
I4IZ36PnXxnLdfMehMDjxeT6PAJDb71oMc85jA h5c ya4b m9OwlGW/e7WgieBB
WGt8NRnnKjwGbwDq7qd2aC2T/ZDBZQFF4wAJjoZop5Wh7NxK8QFV05ES6KXU/hJF
wySbyoSYJb4A3VNrpoEF92vA22aUFn2RrktCXwaaMXoOyLuFDebxOrKgzI5EfhMa
CRBxv4ufNfcAm1uEpqILngou/kxUs5QYW6VaSmV858 bpzcMGR73X1hHY9p0dHO1
QTaIJU/8E91whaCxihDOsyO5jJG6DIhEbwJVABEBAAEAB/0aVKuIWXAFfshJN4RV
22pIxVKmDDx6abLp6R9dL8lmWKTt5URWRnaem8ylWwPQz01reeiQ2v1gEPFFMWgN
U7oHZWdL7I9JG4q3itGF7mi 3iZj4ltBPN1u1w34pTP0kPmd6CW DqLITJUE1Sg0
KhJba4y8eMP5OZ1FM8zpLNtOBF0nW6D0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XVy khDenC6BHgx2D6
ZJIPOs18pko=
=1CCf
-----END PGP PRIVATE KEY BLOCK-----
";
$encryptedPrivateKey=OpenPGP_Message::parse(OpenPGP::unarmor($privateKey2,'PGP PRIVATE KEY BLOCK'));
// Try each secret key packet
foreach($encryptedPrivateKey as $p) {
if(!($p instanceof OpenPGP_SecretKeyPacket)) continue;
$key2 = new OpenPGP_SecretKeyPacket($p->key);
$msg = OpenPGP_Message::parse(OpenPGP::unarmor($cipher_text, 'PGP MESSAGE'));
$decryptor = new OpenPGP_Crypt_RSA($key2);
$decrypted = $decryptor->decrypt($msg);
var_dump($decrypted);
}
Комментарии:
1. Надеюсь, это тестовый ключ, а не ваш РЕАЛЬНЫЙ закрытый ключ. Если это не тестовый ключ, я бы рекомендовал вам отозвать его и сгенерировать новый, а затем никогда не публиковать секретный ключ.
2. Все используемые ключи являются фиктивными ключами, специально предназначенными для этого вопроса.