public function createPrivateKey($passphrase = null, $type = null, $bits = null)
    {
        $options = array();

        if ($type) {
            $type = strtolower($type);

            if (false === isset($this->keyTypes[$type])) {
                throw new InvalidArgumentException(sprintf(
                    'The private key type "%s" is not recognized.',
                    $type
                ));
            }

            $options['private_key_type'] = $this->keyTypes[$type];
        }

        if ($bits) {
            $options['private_key_bits'] = $bits;
        }

        $this->clearBufferedMessages();

        if (false === ($resource = openssl_pkey_new($options))) {
            throw new RuntimeException(sprintf(
                'The private key could not be created: %s',
                openssl_error_string()
            ));
        }

        if (false === openssl_pkey_export($resource, $private, $passphrase)) {
            throw new RuntimeException(sprintf(
                'The private key could not be exported: %s',
                openssl_error_string()
            ));
        }

        openssl_free_key($resource);

        return $private;
    }