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;
    }
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;
    }
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 ; }
Creates a new private key.

@param null|string $passphrase The passphrase.
@param null|string $type       The key type.
@param null|string $bits       The number of bits.

@return string The new private key.

@throws InvalidArgumentException If the private key type is not recognized.
@throws RuntimeException         If the private key could not be created.

@api
Creates a new private key .