Keypairs — php-opencloud 1.12.1 documentation

# Keypairs

## Generate a new keypair

This operation creates a new keypair under a provided name; the public key value is automatically generated for you.

    // Instantiate empty object
    $keypair = $service->keypair();

    // Send to API
    $keypair->create(array(
       'name' => 'jamie_keypair_1'
    ));

    // Save these!
    $pubKey = $keypair->getPublicKey();
    $priKey = $keypair->getPrivateKey();

Get the executable PHP script for this example

## Upload existing keypair

This operation creates a new keypair according to a provided name and public key value. This is useful when the public key already exists on your local filesystem.

    $keypair = $service->keypair();

    // $key needs to be the string content of the key file, not the filename
    $content = file_get_contents('~/.ssh/id_rsa.pub');

    $keypair->create(array(
       'name'      => 'main_key',
       'publicKey' => $content
    ));

Get the executable PHP script for this example

## List keypairs

To list all existing keypairs:

    $keys = $service->listKeypairs();

    foreach ($keys as $key) {

    }

## Delete keypairs

To delete a specific keypair:

    $keypair->delete();