Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Example code for generating a self-signed key

  • Loading branch information...
commit ae7454c504fd638397d0b2e178a457ded2705f18 1 parent 379c79d
@singpolyma authored
Showing with 24 additions and 0 deletions.
  1. +24 −0 examples/keygen.php
View
24 examples/keygen.php
@@ -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();
Please sign in to comment.
Something went wrong with that request. Please try again.