2019-02-10 08:44:29 -05:00
|
|
|
<?php
|
|
|
|
|
2022-11-23 12:25:10 -05:00
|
|
|
use phpseclib3\Crypt\RSA;
|
|
|
|
use phpseclib3\Crypt\RSA\Formats\Keys\PKCS1;
|
|
|
|
|
2021-11-16 15:36:33 -05:00
|
|
|
@include_once dirname(__FILE__).'/../vendor/autoload.php';
|
2019-02-10 08:44:29 -05:00
|
|
|
require_once dirname(__FILE__).'/../lib/openpgp.php';
|
|
|
|
require_once dirname(__FILE__).'/../lib/openpgp_crypt_rsa.php';
|
|
|
|
|
2022-11-23 12:25:10 -05:00
|
|
|
$privateKey = RSA::createKey(512);
|
|
|
|
$publickey = $privateKey->getPublicKey();
|
|
|
|
|
|
|
|
$privateKeyComponents = PKCS1::load($privateKey->toString('PKCS1'));
|
2019-02-10 08:44:29 -05:00
|
|
|
|
|
|
|
$nkey = new OpenPGP_SecretKeyPacket(array(
|
2022-11-23 12:25:10 -05:00
|
|
|
'n' => $privateKeyComponents["modulus"]->toBytes(),
|
|
|
|
'e' => $privateKeyComponents["publicExponent"]->toBytes(),
|
|
|
|
'd' => $privateKeyComponents["privateExponent"]->toBytes(),
|
|
|
|
'p' => $privateKeyComponents["primes"][1]->toBytes(),
|
|
|
|
'q' => $privateKeyComponents["primes"][2]->toBytes(),
|
|
|
|
'u' => $privateKeyComponents["coefficients"][2]->toBytes()
|
2019-02-10 08:44:29 -05:00
|
|
|
));
|
|
|
|
|
|
|
|
$uid = new OpenPGP_UserIDPacket('Test <test@example.com>');
|
|
|
|
|
|
|
|
$wkey = new OpenPGP_Crypt_RSA($nkey);
|
|
|
|
$m = $wkey->sign_key_userid(array($nkey, $uid));
|
|
|
|
|
|
|
|
// Serialize private key
|
|
|
|
print $m->to_bytes();
|
|
|
|
|
|
|
|
// Serialize public key message
|
|
|
|
$pubm = clone($m);
|
|
|
|
$pubm[0] = new OpenPGP_PublicKeyPacket($pubm[0]);
|
|
|
|
|
|
|
|
$public_bytes = $pubm->to_bytes();
|