Example to serialize public key message
This commit is contained in:
parent
f4fabd04e7
commit
d37e91efda
@ -21,4 +21,11 @@ $uid = new OpenPGP_UserIDPacket('Test <test@example.com>');
|
|||||||
$wkey = new OpenPGP_Crypt_RSA($nkey);
|
$wkey = new OpenPGP_Crypt_RSA($nkey);
|
||||||
$m = $wkey->sign_key_userid(array($nkey, $uid));
|
$m = $wkey->sign_key_userid(array($nkey, $uid));
|
||||||
|
|
||||||
|
// Serialize private key
|
||||||
print $m->to_bytes();
|
print $m->to_bytes();
|
||||||
|
|
||||||
|
// Serialize public key message
|
||||||
|
$pubm = clone($m);
|
||||||
|
$pubm[0] = new OpenPGP_PublicKeyPacket($pubm[0]);
|
||||||
|
|
||||||
|
$public_bytes = $pubm->to_bytes();
|
||||||
|
@ -1327,15 +1327,32 @@ class OpenPGP_PublicKeyPacket extends OpenPGP_Packet {
|
|||||||
|
|
||||||
function __construct($key=array(), $algorithm='RSA', $timestamp=NULL, $version=4) {
|
function __construct($key=array(), $algorithm='RSA', $timestamp=NULL, $version=4) {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->key = $key;
|
|
||||||
if(is_string($this->algorithm = $algorithm)) {
|
|
||||||
$this->algorithm = array_search($this->algorithm, self::$algorithms);
|
|
||||||
}
|
|
||||||
$this->timestamp = $timestamp ? $timestamp : time();
|
|
||||||
$this->version = $version;
|
|
||||||
|
|
||||||
if(count($this->key) > 0) {
|
if($key instanceof OpenPGP_PublicKeyPacket) {
|
||||||
$this->key_id = substr($this->fingerprint(), -8);
|
$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);
|
||||||
|
}
|
||||||
|
$this->timestamp = $timestamp ? $timestamp : time();
|
||||||
|
$this->version = $version;
|
||||||
|
|
||||||
|
if(count($this->key) > 0) {
|
||||||
|
$this->key_id = substr($this->fingerprint(), -8);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user