OpenPGP_Crypt_RSA::convert_key PHP Method

convert_key() static public method

static public convert_key ( $packet, $private = false )
    static function convert_key($packet, $private = false)
    {
        if (!is_object($packet)) {
            $packet = OpenPGP_Message::parse($packet);
        }
        if ($packet instanceof OpenPGP_Message) {
            $packet = $packet[0];
        }
        $mod = $packet->key['n'];
        $exp = $packet->key['e'];
        if ($private) {
            $exp = $packet->key['d'];
        }
        if (!$exp) {
            return NULL;
        }
        // Packet doesn't have needed data
        $rsa = self::crypt_rsa_key($mod, $exp);
        if ($private) {
            if ($packet->key['p'] && $packet->key['q']) {
                $rsa->primes = array($packet->key['p'], $packet->key['q']);
            }
            if ($packet->key['u']) {
                $rsa->coefficients = array($packet->key['u']);
            }
        }
        return $rsa;
    }