f8e0e997fc
This commit adds an `example/README.md` file with a little bit of guidance for running the examples themselves. This is helpful because the examples all rely on the presence of a `phpseclib` installation available to the PHP interpreter, and while there is a `composer.json` file to this effect, none of the examples included the Composer `autoload.php` file. This commit makes no modifications to the example code itself, but does `include_once()` the Composer autoload script so that `phpseclib` loads and avoids causing a fatal error when a new user attempts to run the examples to learn how to use the library. This commit also updates the Travis `before_script` build script, dropping the `--dev` argument to the `composer install` command. Current versions of Composer emit a deprecation notice when `--dev` is passed.
33 lines
898 B
PHP
33 lines
898 B
PHP
<?php
|
|
|
|
@include_once dirname(__FILE__).'/../vendor/autoload.php';
|
|
require_once dirname(__FILE__).'/../lib/openpgp.php';
|
|
require_once dirname(__FILE__).'/../lib/openpgp_crypt_rsa.php';
|
|
|
|
$rsa = new \phpseclib\Crypt\RSA();
|
|
$k = $rsa->createKey(512);
|
|
$rsa->loadKey($k['privatekey']);
|
|
|
|
$nkey = new OpenPGP_SecretKeyPacket(array(
|
|
'n' => $rsa->modulus->toBytes(),
|
|
'e' => $rsa->publicExponent->toBytes(),
|
|
'd' => $rsa->exponent->toBytes(),
|
|
'p' => $rsa->primes[2]->toBytes(),
|
|
'q' => $rsa->primes[1]->toBytes(),
|
|
'u' => $rsa->coefficients[2]->toBytes()
|
|
));
|
|
|
|
$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();
|