Example to serialize public key message

This commit is contained in:
Stephen Paul Weber 2015-11-16 10:40:44 -05:00
parent f4fabd04e7
commit d37e91efda
2 changed files with 32 additions and 8 deletions

View File

@ -21,4 +21,11 @@ $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();

View File

@ -1327,6 +1327,22 @@ class OpenPGP_PublicKeyPacket extends OpenPGP_Packet {
function __construct($key=array(), $algorithm='RSA', $timestamp=NULL, $version=4) {
parent::__construct();
if($key instanceof OpenPGP_PublicKeyPacket) {
$this->algorithm = $key->algorithm;
$this->key = array();
// Restrict to only the fields we need
foreach (self::$key_fields[$this->algorithm] as $field) {
$this->key[$field] = $key->key[$field];
}
$this->key_id = $key->key_id;
$this->fingerprint = $key->fingerprint;
$this->timestamp = $key->timestamp;
$this->version = $key->version;
$this->v3_days_of_validity = $key->v3_days_of_validity;
} else {
$this->key = $key;
if(is_string($this->algorithm = $algorithm)) {
$this->algorithm = array_search($this->algorithm, self::$algorithms);
@ -1338,6 +1354,7 @@ class OpenPGP_PublicKeyPacket extends OpenPGP_Packet {
$this->key_id = substr($this->fingerprint(), -8);
}
}
}
// Find self signatures in a message, these often contain metadata about the key
function self_signatures($message) {