Permalink
Browse files

Example code for generating a self-signed key

  • Loading branch information...
1 parent 379c79d commit ae7454c504fd638397d0b2e178a457ded2705f18 @singpolyma committed Jul 25, 2011
Showing with 24 additions and 0 deletions.
  1. +24 −0 examples/keygen.php
View
@@ -0,0 +1,24 @@
+<?php
+
+require dirname(__FILE__).'/../lib/openpgp.php';
+require dirname(__FILE__).'/../lib/openpgp_crypt_rsa.php';
+
+$rsa = new 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[1]->toBytes(),
+ 'q' => $rsa->primes[2]->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));
+
+print $m->to_bytes();

0 comments on commit ae7454c

Please sign in to comment.