cPanel API 2 Functions - SSL::genkey

Warning:

The cPanel API 2 system is deprecated. We strongly recommend that you use UAPI instead of cPanel API 2.


Description

This function generates an SSL key.

Warning:

We strongly recommend that you use the following UAPI function instead of this function:


Important:

In cPanel & WHM version 84 and later, when you disable the Calendars and Contacts, Receive Mail, Web Disk, Webmail, and Web Server roles, the system disables this function.


Examples


WHM API (JSON)

https://hostname.example.com:2087/cpsess###########/json-api/cpanel?cpanel_jsonapi_user=user&cpanel_jsonapi_apiversion=2&cpanel_jsonapi_module=SSL&cpanel_jsonapi_func=genkey&host="example.com"&keysize="4096"
Note:

For more information, read our Calls from the WHM API documentation.


LiveAPI PHP Class

$cpanel = new CPANEL(); // Connect to cPanel - only do this once.

// Generate a new SSL key for example.com.
$generate_new_key = $cpanel->api2(
    'SSL', 'genkey',
    array(
        'host'            => 'example.com',
        'keysize'         => '4096',
    )
);
Note:

For more information, read our Guide to the LiveAPI System.


LiveAPI Perl Module

my $cpliveapi = Cpanel::LiveAPI->new(); # Connect to cPanel - only do this once.

# Generate a new SSL key for example.com.
my $generate_new_key = $cpliveapi->api2(
    'SSL', 'genkey',
    {
        'host'            => 'example.com',
        'keysize'         => '4096',
    }
);
Note:

For more information, read our Guide to the LiveAPI System.


cPanel Tag System (deprecated)

Warnings:
  • In cPanel & WHM version 11.30 and later, cPanel tags are deprecated . We strongly recommend that you only use the LiveAPI system to call the cPanel APIs. Examples are only present in order to help developers move from the old cPanel tag system to our LiveAPI .
  • cPanel API 2 calls that use cPanel tags vary in code syntax and in their output.
  • For more information, read our Deprecated cPanel Tag Usage documentation.

Command Line

cpapi2 --user=username SSL genkey host=example.com keysize=4096
Notes:
  • You must URI-encode values.
  • username represents your account-level username.
  • You must include the --user=username option.
  • For more information and additional output options, read our Guide to cPanel API 2 documentation or run the cpapi2 --help command.
  • If you run CloudLinux™, you must use the full path of the cpapi2 command:
    /usr/local/cpanel/bin/cpapi2

Output (JSON)

{
  "cpanelresult": {
    "apiversion": 2,
    "func": "genkey",
    "data": [
      {
        "output": "Private key generated!",
        "result": 1,
        "key": "-----BEGIN RSA PRIVATE KEY-----\nMIIJJwILAAMBAgEA4yilqsoCdEpiNOyLcPJ4FLT7vgwaLdOBeJLTMUeV2uZM4v65\n\/tiZe7H0soDp1C55SCrSuPeRa7Lq7RUZ+F5p67BgRR19rmerKGxfN7N5Vu97pfTw\nW1f+lVsxUF\/56lVeoAmm4okU98xJFZVTbI8ZHGJbUMYfLPy0OrA+gNwMHqMVOv1B\nSgpbEWCILMvnvtp0rwPutjnPVX2Dj40ia40L4Wqvp+0Yg7mZyhIOl+q6VZVIdXZs\nlR4ZywfRBYt3ieFBDYMyNw9wN3Xy44fCpHc77+ho84W3BqrGaWSSDyf6UkZGD5mf\nohGf2JSp+c8J6H7hsxo7pta3K1diVXFOSfnaA+k56zW445XruwYs\/SN\/zvGetGi6\nuqhMAcVRQcYCmLCixcC6RkcUx3exxgR4q3gthDnFvWC4+NuTh8\/K0BcxcuCEhRug\n\/MfVfO3+f7RJFSJPFb9m9Lf4HHBSVkDP5WtG4XiBKCe++9Wuvxbd4QxS7YrnSopN\nKxkuHKswH8ONpADMYDqfLODMhNrslHNHu95Nv7AlQr8weLqMGWMp7GFqzXcl39Rn\nVkF4Bxd3bAAsMN8\/JuerMKCPjTTDrfzVFZcm2x2hobjYDdY1xfIstYVtbyFkUHZP\n2RPPBaPUAtt&czrKGVF8a2vdIKRiey5SZ5qu9c\/mGri3oz7Lkk7qkNPAqDMCAwEA\nAQKCAgA3f9raG3j2CKZt381Bzzvfc0h+al6LC736Q4Ut6RuH2\/S1ER9IUItPWW87\nnZuDp8ciBr13W0nRNmmHezxZHlgqqXEb8dSfI90Bh1jMNyFSSDihl3KSHrGotBsc\nVBavViREXZdUicGBuXuxtkYno96yvKUq2v0K9MLkA+OBgEHFynqJaw7klBsj573d\nlAQO8TjI+eD8zKsHbB8Ul5rtRAy\/Cl3YXWk75cDZSggevc7A0jRd3o0w8aXDoSlE\nfYq7OTm3n3JJWZBF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WDbFx5AEB\/G9tq\/zmTqQkuo39dvgl30w\nyZGRNwc1aFf1Kxeven10\/JN9ipp0mTa7NYSdn0RAe9ZRp5cCkgmktqmB0g==\n-----END RSA PRIVATE KEY-----"
      }
    ],
    "event": {
      "result": 1
    },
    "module": "SSL"
  }
}
Note:

Use cPanel's API Shell interface (cPanel >> Home >> Advanced >> API Shell) to directly test cPanel API calls.


Parameters

Parameter Type Description Possible values Example
host string

Required

The key's hostname.

A valid domain or subdomain name.


example.com
keysize integer

The key size, in bytes.

This parameter defaults to 1024.

An integer that is between 1024 and 4096. If you specify an invalid value, the system uses the default value (1024).

4096

Returns

Return Type Description Possible values Example
output string

A message of success or a reason for failure.

  • Private key generated!
  • A string that describes the error.
This is an error message.
result Boolean

Whether the function succeeded.

  • 1 — The function succeeded.
  • 0 — The function failed.
1
key string The certificate's key.

The key file contents.

This data always begins with -----BEGIN RSA PRIVATE KEY----- and ends with -----END RSA PRIVATE KEY-----.

-----BEGIN RSA PRIVATE KEY----- MIIJJwIBAAKCAgEA4yilqsoCdEpiNOyLcPJ4FLT7vgwaLdOBeJLTMUeV2uZM4v65 /tiZe7H0soDp1C55SCr3uEIEa7Lq7RUZ+F5p67BgRR19rmerKGxfN7N5Vu97pfTw W1f+lVsxUF/56lVeoAmm4okU98xJHiGGlI8ZHGJbUMYfLPy0OrA+gNwMHqMVOv1B SgpbEWCILMvnvtp0rwPutjnPVX2Dj40ia40L4Wqvp+0Yg7mZyhIOl+q6VZVIdXZs lR4ZywfRBYt3ieFBDYMyNw9wN3Xy44fCpHc77+ho84W3BqrGaWSSDyf6UkZGD5mf ohGf2JSp+c8J6H7hsxo7pta3K1diVXFOSfnaA+k56zW445XruwYs/SN/zvGetGi6 uqhMAcVRQcYCmLCixcC6RkcUx3exxgR4q3gthDnFvWC4+NuTh8/K0BcxcuCEhRug /MfVfO3+f7RJFSJPFb9m9Lf4HHBSVkDP5WtG4XiBKCe++9Wuvxbd4QxS7YrnSopN KxkuHKswH8ONpADM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