I want to create the pgp key with php.
I'm using the Crypt_GPG library to do this. I have no problem coding and decoding with an external key.
If I want to produce a key here, he gives me the fingerprint.
https://github.com/pear/Crypt_GPG/blob/master/tests/KeyGeneratorTest.php
$generator = new \Crypt_GPG_KeyGenerator(array('binary' => '/usr/bin/gpg2', 'homedir' => 'pgphome/', 'debug' => false));
$key = $generator->setExpirationDate(2000000000)->generateKey(
new Crypt_GPG_UserId(
'Test Keypair <generate-test#example.com>'
)
);
I hope to have private and public keys instead of fingerprints. Like this;
-----BEGIN PGP PRIVATE KEY BLOCK-----
Version: BCPG C# v1.6.1.0
lQOsBFzmomwBCACKQjZRXY2TSIEUr+S5V3jK6hA+U/7W2y7X9KJojcNSQY9rDh7E
7OtNQaXEpYeJAd4b9S1ZPMAZJ+wVFl0apOGzcjRT1a/s0GrIyq+SeI32CcHXA8Kh
......
Lji4mK7gT8LbOdeZehPgIp1LH3s9cG/tpyNUzHBZwgTtS6bEvgFSMxBVKRHWJH0k
Yfmc85ah7fZZkmbek9x5W5KKhzPgujCrZT/d0xiBIRp7cr8DAcJ2
=ehq/
-----END PGP PRIVATE KEY BLOCK-----
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: BCPG C# v1.6.1.0
mQENBFzmomwBCACKQjZRXY2TSIEUr+S5V3jK6hA+U/7W2y7X9KJojcNSQY9rDh7E
7OtNQaXEpYeJAd4b9S1ZPMAZJ+wVFl0apOGzcjRT1a/s0GrIyq+SeI32CcHXA8Kh
.....
vy44uJiu4E/C2znXmXoT4CKdSx97PXBv7acjVMxwWcIE7UumxL4BUjMQVSkR1iR9
JGH5nPOWoe32WZJm3pPceVuSiocz4Lowq2U/3dMYgSEae3K/AwHCdg==
=jEjZ
-----END PGP PUBLIC KEY BLOCK-----
Related
I'm trying to convert key pair from PEM format :
-----BEGIN PUBLIC KEY-----
-----END PUBLIC KEY-----
Into XML format :
<RSAKeyValue>
<Exponent> </Exponent>
<Modulus> </Modulus>
</RSAKeyValue>
Is it possible using only openssl as I generate the keys through it ?
nb : my keys are stored into $privKey and $pubKey variable for test purpose, so I want to be able to $echo the XML format key and not store it into a file for the moment.
nb' : I have tried using phpseclib with an exemple found here but it gives me this error "Uncaught Error: Class "BaseController" not found in ..."
Thanks for your help
Here is the PHP code :
<?php
$config = array
(
'config' => 'C:\xampp\htdocs\crypto\openssl.cnf',
'default_md' => 'sha512',
'private_key_bits' => 4096,
'private_key_type' => OPENSSL_KEYTYPE_RSA,
);
$keypair = openssl_pkey_new($config);
openssl_pkey_export($keypair, $privKey, null, $config);
$publickey = openssl_pkey_get_details($keypair);
$pubKey = $publickey['key'];
use phpseclib3\Crypt\RSA;
echo $pubKey->toString("XML");
echo "$privKey";
?>
The conversion of a PEM encoded key in X.509/SPKI format to XML format can be done with phpseclib as follows:
use phpseclib3\Crypt\PublicKeyLoader;
$x509pem = '-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAunF5aDa6HCfLMMI/MZLT
5hDk304CU+ypFMFiBjowQdUMQKYHZ+fklB7GpLxCatxYJ/hZ7rjfHH3Klq20/Y1E
bYDRopyTSfkrTzPzwsX4Ur/l25CtdQldhHCTMgwf/Ev/buBNobfzdZE+Dhdv5lQw
KtjI43lDKvAi5kEet2TFwfJcJrBiRJeEcLfVgWTXGRQn7gngWKykUu5rS83eAU1x
H9FLojQfyia89/EykiOO7/3UWwd+MATZ9HLjSx2/Lf3g2jr81eifEmYDlri/OZp4
OhZu+0Bo1LXloCTe+vmIQ2YCX7EatUOuyQMt2Vwx4uV+d/A3DP6PtMGBKpF8St4i
GwIDAQAB
-----END PUBLIC KEY-----';
$publicKey = PublicKeyLoader::load($x509pem); // import public PEM key
$xmlFormattedKey = $publicKey->toString("XML"); // export public XML key
print($xmlFormattedKey);
The output is:
<RSAKeyValue>
<Modulus>unF5aDa6HCfLMMI/MZLT5hDk304CU+ypFMFiBjowQdUMQKYHZ+fklB7GpLxCatxYJ/hZ7rjfHH3Klq20/Y1EbYDRopyTSfkrTzPzwsX4Ur/l25CtdQldhHCTMgwf/Ev/buBNobfzdZE+Dhdv5lQwKtjI43lDKvAi5kEet2TFwfJcJrBiRJeEcLfVgWTXGRQn7gngWKykUu5rS83eAU1xH9FLojQfyia89/EykiOO7/3UWwd+MATZ9HLjSx2/Lf3g2jr81eifEmYDlri/OZp4OhZu+0Bo1LXloCTe+vmIQ2YCX7EatUOuyQMt2Vwx4uV+d/A3DP6PtMGBKpF8St4iGw==</Modulus>
<Exponent>AQAB</Exponent>
</RSAKeyValue>
For key generation OpenSSL can be used as in your code. However, the exported PEM key must be imported in the phpseclib part as shown in the code above (this import is missing in your code):
// Key generation with OpenSSL
$config = array(
"private_key_bits" => 2048,
"private_key_type" => OPENSSL_KEYTYPE_RSA,
);
$res = openssl_pkey_new($config); // create key resource using $config
//openssl_pkey_export($res, $privKey); // export private key (PEM encoded, PKCS#8 format); not required for this example
$pubKeyDetails = openssl_pkey_get_details($res);
$x509pem = $pubKeyDetails["key"]; // export public key (PEM encoded, X.509 format)
// Key conversion with phpseclib
$publicKey = PublicKeyLoader::load($x509pem); // import public PEM key generated with OpenSSL
$xmlFormattedKey = $publicKey->toString("XML"); // export public XML key
print($xmlFormattedKey);
Alternatively, also key generation can be done with phpseclib:
use phpseclib3\Crypt\RSA;
$privateKey = RSA::createKey(2048); // generate private key
$xmlFormattedKey = $privateKey->getPublicKey()->toString("XML"); // export public XML key
print($xmlFormattedKey);
See source code below to reproduce this issue. Step 1 encrypts the message using gnupg while step 2 decrypts the message from step 1 using openpgp-php. To execute code ensure you have PHP gnupg and openpgp-php installed. (see singpolyma
/
openpgp-php ) for openpgp-php documentation.
What I am trying to achieve
I have a backend server and a mobile app which can only communicate through email. For simplicity assume that step 1 is the backend server and step 2 is the mobile client. Messages flow back and forth between server and client. The backend server should be able to encrypt a message meant for the mobile app which in return decrypts the message and sends an encrypted reply to the backend.
<?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
ZnJpLTJAZXhhbXBsZS5jb20+iQFOBBMBCgA4FiEEFL28kQaiGEUK7cm+n15EvbMd
HkgFAl+xv34CGy8FCwkIBwIGFQoJCAsCBBYCAwECHgECF4AACgkQn15EvbMdHkhF
IggAsvxVIZOTo9SrNvEERUz05X8z7+CNR1m4rCL4Q5mtaFhL0RcsH2FpLqd7+96J
txFBRL5XaUiDQeVc1qzSNnr062DtR0jxvR59Rg+aBfyX2haNHKbD3Dw6e2WaDXMe
OkhJjS2h16Wc+4ztRerGQ0vI+fTaImrs43uCuzKrMPo39/hxewv5BXRpkXrSCZ/X
9jTH+XQxBsEaXe+W9pW5tXpSSVUkccBwuKWJBygzI41PQ+Xi39tn+TxVk+kFDASV
7uvYMPU3IBdbQ/F8xcnb6q6uH2r7lIZRUSsj/H3SHlcDwiBXZgez49Re9eZjFp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Z422BLYEt8qQrxLoOI6gUzz/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
mx8UjSW4CcHhwwJXegLn3hWz/okcg5/2hsfa6iAtCNzTL1KUimbxUEqKK6/b0y56
858+cuLPL5wUjY0ru0GaqApOIugqkWVgE30Llg5w43g7piL0NnqABKpG74hAxIeN
6xSd3uDCmIPkyglX95crfYA3qzwl5KC/Jnn5Vr9ZCdDk1aipCNQtdxKYJueSardH
T4CLskqG/SUC9bXOZJYqntC0gWx2nk47WhPKp5xlpXt3RuPklWcM7y1Pj9qzY4fb
Iw23bY0e555LTBpQjZWM0j44lC1Rx6BbaSGCHb3n3kySeZa8ytmA+Jf9M+UYoTHO
ydEEAOIsjHpcILkW9oa6V/amTRDntpD1IWeWDKi41BWaVPelxkPJfn4cmlb6JQnS
1/NqsXzCBKidMQSPs4hpexnEPOxOh8R3h3+UTNZHbWHcyfTt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lKcfr
eZcg9EpAiQJsBBgBCgAgFiEEQ8t2sG16CAItmf8VQEnNax3vDvMFAl+xvukCGy4B
QAkQQEnNax3vDvPAdCAEGQEKAB0WIQRgdT431gF+2C6i4ZNGvDeTCa5Q0gUCX7G+
6QAKCRBGvDeTCa5Q0kzaB/9ZQ1sKCgf4vKfgnMSgrS7JzU6EgrJuW35A8lrpLuSL
JFXpiy6r08HTCeHtC40941ELVa27wRQ3joCwnlKWklgTLRDq2/u+VGtnoJSQUSw1
9+eav/aKiTPr661qstR+erikI8WEWmanWSl2nxrqYx22t0a9lR9S0LtVgmRL4Lp/
cXAcnROXs+BkfvjuZZV7dOMIyxSzS0wTd+bcNklvxZiQ0rQetBqiZFTDbusytyp0
+pTzmPTXv3pUnaw8rn4kN20/q2lL8igxkvj2+rNDB+HEJdyXsMi0qEF/W1kLwKCl
O91sJmg+0h5MKFL2IHADVDkpBAj38ea8LFNRZ+NCMzb3gPcIAMS6saiX5DC/6GSr
jFbqWY9QstPHDFW3+1BYV+Fs0W2UutZ0vmAzN8LO7mKVXNalemKM82osRCwFXSal
uoX5o6GcqS08DGBJOaFiWxQ5cSSBEYNeq2/Esq6ejW4bIlWUYRmQx6/1dST2vgx3
TH4gbNpVkrwNHijqUzuIr6qDnk+reYrNqq57WPuRJ86BEtW3dnVU4oPSLdC2reQW
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/Ko6dsYyPojxyZAE22BAA96LbFKGV4FokBMQ1WVE52/aEIp7i+7rf
W5auFxk/xFz9k/EkllwLZMmeyaSRNV3zGrQJAuq4NwWydsCUT9FmmnH7FovMwSpy
RAXsnErAUI3GB3Ot+UO/1OQb1FzX834YPes/yd1+x05aEht5t2g7trgXnpY4yWjC
9H8FDxClpLl9JvJ9uajw7iVp96uWvbd7MazTWC74IDJ7av2syodGaTNwfZ7MUKR3
C9dOBxp+bayWTOhCP8vvBlT9MD5QZJL3IHZ5a11oMGJnnty2ynw/tOonLy2OZYYm
tf6bm9ERgA1K67yOROoToBW5AQ0EX7G+6QEIAJp5vHuJsOQ2egLDQAZtW6/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+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
KhJba4y8eMP5OZ1FM8zpLNtOBF0nW6D0q0/QZKRRtivTrJDrERgsfSwFAbXvxdig
eQtXcP4BWtR7c0Xx+aHIjEkE7etgTt7BZmoe5dkotHeV4fVFH8GzBrnN8FvAAsNe
vQgE6uTGGHFsIRfCX4GF9SYMcmHCCUVi9re/5GSaGb26Bl348QwHh1Yf3SqULKu7
abUhBAD+W9512kxJSCSj5nhliIN6ce8+bvM7n34dlTG0HqBE2/ygfXllVapyHZbP
ubbY4sFSlrv8ROJcu4ieAfa/ho+adKnjYUiiKhbVD3umJsfSTosyTRhsSWldGRyc
3v16IQrudVFB300dn0CPi57+sXPNZprGjI+NqpnD1+hDAW/5sQQA/1n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xv34C
Gy4BQAkQn15EvbMdHkjAdCAEGQEKAB0WIQR3zuJGs/Iyh6FlFq91FMPrcW4x3gUC
X7G/fgAKCRB1FMPrcW4x3ozOB/45X6+t9JeUSBp1e1jfr+CJMAlf6HiSsQd7BpA1
UFGU42oOBqFNpT7q7TwcUlbf9JHq8qL10SuPgIot04vDQSsaMxWc8X/E4OCDo9Wh
OT5CwmjJLzmQwhWzpAlhw93sQTJY7oKyW3lasxyDjBhIDHz0lagNfU6S5ZkR8U5S
2qoM6VRrbDVP224HXXjhLUvbChF+G5MvWaAOExPvz2Sc69jcQaQ5D4PM65qfatoJ
ZEdQjREnYGU4c7ZqPPunQSbIlMzufFsu2mMM1/mLKMA12+VPoMbrzoMoJD4ENNsF
jXmYjlDlwLrs1pYDu7bjm5Aqz1iylMrup+eiv5TqXFX93PR50+UH/A0gg6LkuBJO
J9G1TCN/G32NmB3/NOhLPZgdF9E36cxV6/EiOwYP2YVG4eBS+Sajk4PieYupNI91
rwU5O9gRUCekv3TbI7F41oin/tF9++RoLpGyRjOT4P7PsBfg9PTIzHBlVmIBo88J
P14IhRcNnajX81Mw01esspl2+bkX1MgmZ7SPoODZ422BLYEt8qQrxLoOI6gUzz/N
pY4OpoRSQdx3TEmHKzLIIWZgkMC1IwNX4Jc4gLF8pMD4miSwm5RRlHzop7APmCs6
F7jC+evoH3xWQTvkq7Rrh0ykvZOeX+kEvEfglFrFDM2GE0XVy+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);
}
I am trying to create a JWT token. The other server is storing the public key in a single line and using that for validation.
Also, the public key being used for validation is in single line.
So, to generate the correct JWT token, what I think is I should also use the private key in a single line (may be with \n or may be without).
I am using openssl_sign to generate the token, which uses openssl_reource as key. I get that paramter from openssl_pkey_get_private.
But problem which happens in this case is, it either accepts the pem file path, or the key in PEM string format. So, if I pass the private_key as a single line, it doesn't give me the required output.
So, how can I resolve this. As I see other language libraries able to generate signature by passing private key in a single line.
In PHP the key can be formatted with line breaks or as a one-liner (with \n). Both works. In the following example I use a 512-bit encrypted RSA-key for simplicity (although in practice a larger key (>= 2048 bit) must be used for security reasons):
<?php
// Private key: 512 bit for simplicity
// Passphrase: MyPassphrase
// openssl genrsa -aes256 -out private.pem 512
$privKeyEnc = "-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-256-CBC,8F2D6F9594B3D379BF9D9748BD174458
RP2fyz1VNBKHiCadC5B9fjxV7z7AMAqbsN2vykFfPhdUFsxlJaecEeTMT7s6IbZN
Pr80+ljLjJ0SxJiK+j8DAc/Wrf+qyYUFcWbsvOhUIPyB5ww9+mEeIERJCigsyZJ7
k/Apau/BypdC9vCXKB3wM9FcmvP1g/ZwVoXfN3TIPEfWTktvuf74yFNoIaVbZAK/
+tzAGduu9wLkr6WTq4Isqy/IPjVCp9VwH1wNnz+hjkO7oELcCpFieIvAidUMKBR9
EdexLQCimbOl2wlfRNLincK8+FDOVWx6ElFFQlhzyWQCt8ed1fdiAggKxOco4Ww2
tFjIzaO4KXlbc9JFGd9PzigpftN/aHbk3c+x0E+3q5u8eySai4vgk38s1KaE7rn/
rarCgtGxOlbbTkI3opkjIrGlrsEyexKtS23mI/Dgcco=
-----END RSA PRIVATE KEY-----";
// One-liner using \n
$privKeyEnc_1Line = "-----BEGIN RSA PRIVATE KEY-----\nProc-Type: 4,ENCRYPTED\nDEK-Info: AES-256-CBC,8F2D6F9594B3D379BF9D9748BD174458\n\nRP2fyz1VNBKHiCadC5B9fjxV7z7AMAqbsN2vykFfPhdUFsxlJaecEeTMT7s6IbZN\nPr80+ljLjJ0SxJiK+j8DAc/Wrf+qyYUFcWbsvOhUIPyB5ww9+mEeIERJCigsyZJ7\nk/Apau/BypdC9vCXKB3wM9FcmvP1g/ZwVoXfN3TIPEfWTktvuf74yFNoIaVbZAK/\n+tzAGduu9wLkr6WTq4Isqy/IPjVCp9VwH1wNnz+hjkO7oELcCpFieIvAidUMKBR9\nEdexLQCimbOl2wlfRNLincK8+FDOVWx6ElFFQlhzyWQCt8ed1fdiAggKxOco4Ww2\ntFjIzaO4KXlbc9JFGd9PzigpftN/aHbk3c+x0E+3q5u8eySai4vgk38s1KaE7rn/\nrarCgtGxOlbbTkI3opkjIrGlrsEyexKtS23mI/Dgcco=\n-----END RSA PRIVATE KEY-----";
// Public key:
// Passphrase: MyPassphrase
// openssl rsa -in private.pem -outform PEM -pubout -out public.pem
$pubKey = "-----BEGIN PUBLIC KEY-----
MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAMjYQLbdIVgKX1mSyKijOIpmlB9YWui1
KoCniRNHUPEsxth+o9fZXZMo1gzh9ZlFs6VLiyU7kv2+5QElOnhNzwcCAwEAAQ==
-----END PUBLIC KEY-----";
// One-liner using \n
$pubKey_1Line = "-----BEGIN PUBLIC KEY-----\nMFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAMjYQLbdIVgKX1mSyKijOIpmlB9YWui1\nKoCniRNHUPEsxth+o9fZXZMo1gzh9ZlFs6VLiyU7kv2+5QElOnhNzwcCAwEAAQ==\n-----END PUBLIC KEY-----";
$dataToSign = 'The quick brown fox jumps over the lazy dog.';
// Signing
//$privateKey = openssl_pkey_get_private("$privKeyEnc", "MyPassphrase"); // also works
$privateKey = openssl_pkey_get_private("$privKeyEnc_1Line", "MyPassphrase");
openssl_sign($dataToSign, $signature, $privateKey, 'sha256');
$signatureBase64 = base64_encode($signature);
print("Signature (Base64): ".$signatureBase64."<br>");
// Verifying
$publicKey = openssl_pkey_get_public("$pubKey");
//$publicKey = openssl_pkey_get_public("$pubKey_1Line"); // also works
$verified = openssl_verify($dataToSign, $signature, $publicKey,'sha256');
print("Verification: ".$verified."<br>");
/*
Output:
Signature (Base64): KVuUd+xy6at0emmhF20rbiD9lWzIN9euwKbeEm7aMvxqEkJ68HrjAoDJ37R3QGPI24woXY3TON9pahAhx+YNhQ==
Verification: 1
*/
?>
To authenticate a google oauth2 token, I'm generating a public key for kid "b863b534069bfc0207197bcf831320d1cdc2cee2" from the modulus (n) and exponent (e) from:
https://www.googleapis.com/oauth2/v3/certs
{
"alg": "RS256",
"n": "8h6tCwOYDPtzyFivNaIguQVc_yBO5eOA2kUu_MAN8s4VWn8tIfCbVvcAz3yNwQuGpkdNg8gTk9QmReXl4SE8m7aCa0iRcBBWLyPUt6TM1RkYE51rOGYhjWxo9V8ogMXSBclE6x0t8qFY00l5O34gjYzXtyvyBX7Sw5mGuNLVAzq2nsCTnIsHrIaBy70IKU3FLsJ_PRYyViXP1nfo9872q3mtn7bJ7_hqss0vDgUiNAqPztVIsrZinFbaTgXjLhBlUjFWgJx_g4p76CJkjQ3-puZRU5A0D04KvqQ_0AWcN1Q8pvwQ9V4uGHm6Bop9nUhIcZJYjjlTM9Pkx_JnVOfekw",
"use": "sig",
"kid": "b863b534069bfc0207197bcf831320d1cdc2cee2",
"e": "AQAB",
"kty": "RSA"
}
I then create the RSA 256 public key in php with:
$rsa = new Crypt_RSA();
$modulus = new Math_BigInteger(base64url_decode($cert["n"]), 256);
$exponent = new Math_BigInteger(base64url_decode($cert["e"]), 256);
$rsa->loadKey(array('n' => $modulus, 'e' => $exponent));
$rsa->setPublicKey();
$public_key = $rsa->getPublicKey();
This generates public key:
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuopEuQyOKMsQq90I/5on
1nNBPc7stMvsN1HC+Pgyu8nJ1qWwaAAqIv4edo2oG/Bo3eg6p+OjG3nbFL62S6hE
aJLUVfxhW5GQuxQlsvaA2MsZuZCRyKTv8bm641wM+biGVZLiDsLRylVdpxf4aGa9
9zZw+QZMVKL4f9B4SunyTugTaCIu8LBOQesCQp/QJaUjqMDhfEvoFQXiCn6zo3rW
EWBiKxiFBizH9jSfWimJecFhn0Vlv/Vs7pRb0X2y66VS3gTvR6/A3ooNz3tYAJPM
GoE8fAiEghYXXHjmWmgdRx9Qt9sa/ACwv7yx0Th27fw+rrsMSrUyaqRpn/fjIMTu
sQIDAQAB
-----END PUBLIC KEY-----
This same method worked with dozens of other RS256 kid's from google, but the public key does not work with this particular kid.
I am verifying the signature with:
openssl_verify($payload_to_verify, $safe_signature, $public_key, OPENSSL_ALGO_SHA256);
Which responds with '0' for failure.
Edit #2: Found google's version of the public key at:
https://www.googleapis.com/oauth2/v1/certs
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA8h6tCwOYDPtzyFivNaIg
uQVc/yBO5eOA2kUu/MAN8s4VWn8tIfCbVvcAz3yNwQuGpkdNg8gTk9QmReXl4SE8
m7aCa0iRcBBWLyPUt6TM1RkYE51rOGYhjWxo9V8ogMXSBclE6x0t8qFY00l5O34g
jYzXtyvyBX7Sw5mGuNLVAzq2nsCTnIsHrIaBy70IKU3FLsJ/PRYyViXP1nfo9872
q3mtn7bJ7/hqss0vDgUiNAqPztVIsrZinFbaTgXjLhBlUjFWgJx/g4p76CJkjQ3+
puZRU5A0D04KvqQ/0AWcN1Q8pvwQ9V4uGHm6Bop9nUhIcZJYjjlTM9Pkx/JnVOfe
kwIDAQAB
-----END PUBLIC KEY-----
My generated public key is different. Why my generated public key is wrong?
I confirm that the key is not correctly converted by the RSA Crypt package.
Wrong key
Good key
I tried to convert that key with another application (web-token/jwt-app) and I got the same result as the one provided by Google.
curl -OL https://github.com/web-token/jwt-app/raw/gh-pages/jose.phar
curl -OL https://github.com/web-token/jwt-app/raw/gh-pages/jose.phar.pubkey
chmod +x jose.phar
./jose.phar key:convert:pkcs1 '{"alg": "RS256","n": "8h6tCwOYDPtzyFivNaIguQVc_yBO5eOA2kUu_MAN8s4VWn8tIfCbVvcAz3yNwQuGpkdNg8gTk9QmReXl4SE8m7aCa0iRcBBWLyPUt6TM1RkYE51rOGYhjWxo9V8ogMXSBclE6x0t8qFY00l5O34gjYzXtyvyBX7Sw5mGuNLVAzq2nsCTnIsHrIaBy70IKU3FLsJ_PRYyViXP1nfo9872q3mtn7bJ7_hqss0vDgUiNAqPztVIsrZinFbaTgXjLhBlUjFWgJx_g4p76CJkjQ3-puZRU5A0D04KvqQ_0AWcN1Q8pvwQ9V4uGHm6Bop9nUhIcZJYjjlTM9Pkx_JnVOfekw","use": "sig","kid": "b863b534069bfc0207197bcf831320d1cdc2cee2","e": "AQAB","kty": "RSA"}'
Best would be to warn phpseclib/phpseclib about that issue.
I manage to generate private / public keys using the following script :
$res = openssl_pkey_new(array('private_key_bits' => 2048,'private_key_type' => OPENSSL_KEYTYPE_RSA));
openssl_pkey_export($res, $privkey);
file_put_contents('test.private.key', $privkey);
$pubkey = openssl_pkey_get_details($res);
$pubkey = $pubkey["key"];
file_put_contents('test.public.key', $pubkey);
The generated files :
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAwQ5L0JQ2G5zGhC4uDISo6krN/mKrBuULYhrVL9Zdve+C9DuH
6uDTRCC07PvIKcHVj13vKB4YvRlwCCAxHg5p34P3W9vjmrI91rdVJ31noRvJ/i5Z
jNBfy7c8NrIOA6m4gicfPbozuQU741jLSncdQuyZRrADbFWppIz/mLm5WDZk6+NU
yAM2o0jvDsKE7i3sT+IKJpjUC8mE+RONIooNtHB3GJarsCKg5L6e0EaGXlVp9Mez
lSSn/Z5p1Wu3GJq02lNGLT5BVgCfE7ajBDZWRDG+Mbp4/YCt/zXz5XWm2/BxD78c
2wH3qMs/bIjvq5MTta4E2VQTSCxI5fMjRUf5QQIDA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dKdMHzmHd+r2rbCTqT/NOIoip1zYpEGpiginkZcpy7Mz4iBL1Y
H7a2sa5k9Pykm2sQYoFPM8vn7halDcuAV7mjiV4XyiM5wRRWHTqSoUgjElexE0W5
HoQvWv10NBFqySMSfCm+YFXZGY17usxAJPSIySHzoTVRJEIjAw0G
-----END RSA PRIVATE KEY-----
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwQ5L0JQ2G5zGhC4uDISo
6krN/mKrBuULYhrVL9Zdve+C9DuH6uDTRCC07PvIKcHVj13vKB4YvRlwCCAxHg5p
34P3W9vjmrI91rdVJ31noRvJ/i5ZjNBfy7c8NrIOA6m4gicfPbozuQU741jLSncd
QuyZRrADbFWppIz/mLm5WDZk6+NUyAM2o0jvDsKE7i3sT+IKJpjUC8mE+RONIooN
tHB3GJarsCKg5L6e0EaGXlVp9MezlSSn/Z5p1Wu3GJq02lNGLT5BVgCfE7ajBDZW
RDG+Mbp4/YCt/zXz5XWm2/BxD78c2wH3qMs/bIjvq5MTta4E2VQTSCxI5fMjRUf5
QQIDAQAB
-----END PUBLIC KEY-----
Could someone tell me how to retrieve my keys, in order to encrypt / decrypt files. I'm trying the following :
$privkey = openssl_pkey_get_private('file://test.private.key')
$pubkey = openssl_pkey_get_public('file://test.public.key')
But these functions return false...
Thanks
Ok sorry forget about this post, I just tried to make it hard where it's very simple : A file_get_contents('test.public.key') is enough to retrieve the keys ;)