2023-01-29 15:27:11 +08:00
## Objects
<dl>
<dt><a href="#forge ">forge</a> : <code>object</code></dt>
<dd><p>Legacy node-forge crypto interface</p>
<p>DEPRECATION WARNING: This crypto interface is deprecated and will be removed from acme-client in a future
major release. Please migrate to the new <code>acme.crypto</code> interface at your earliest convenience.</p>
</dd>
</dl>
2024-11-14 00:20:17 +08:00
## Constants
2023-01-29 15:27:11 +08:00
<dl>
2024-11-14 00:20:17 +08:00
<dt><a href="#createPublicKey ">createPublicKey</a> ⇒ <code>Promise.<buffer></code></dt>
2023-01-29 15:27:11 +08:00
<dd><p>Create public key from a private RSA key</p>
</dd>
2024-11-14 00:20:17 +08:00
<dt><a href="#getPemBody ">getPemBody</a> ⇒ <code>string</code></dt>
2023-01-29 15:27:11 +08:00
<dd><p>Parse body of PEM encoded object from buffer or string
If multiple objects are chained, the first body will be returned</p>
</dd>
2024-11-14 00:20:17 +08:00
<dt><a href="#splitPemChain ">splitPemChain</a> ⇒ <code>Array.<string></code></dt>
2023-01-29 15:27:11 +08:00
<dd><p>Split chain of PEM encoded objects from buffer or string into array</p>
</dd>
2024-11-14 00:20:17 +08:00
<dt><a href="#getModulus ">getModulus</a> ⇒ <code>Promise.<buffer></code></dt>
2023-01-29 15:27:11 +08:00
<dd><p>Get modulus</p>
</dd>
2024-11-14 00:20:17 +08:00
<dt><a href="#getPublicExponent ">getPublicExponent</a> ⇒ <code>Promise.<buffer></code></dt>
2023-01-29 15:27:11 +08:00
<dd><p>Get public exponent</p>
</dd>
2024-11-14 00:20:17 +08:00
<dt><a href="#readCsrDomains ">readCsrDomains</a> ⇒ <code>Promise.<object></code></dt>
2023-01-29 15:27:11 +08:00
<dd><p>Read domains from a Certificate Signing Request</p>
</dd>
2024-11-14 00:20:17 +08:00
<dt><a href="#readCertificateInfo ">readCertificateInfo</a> ⇒ <code>Promise.<object></code></dt>
2023-01-29 15:27:11 +08:00
<dd><p>Read information from a certificate</p>
</dd>
2024-11-14 00:20:17 +08:00
<dt><a href="#createCsr ">createCsr</a> ⇒ <code>Promise.<Array.<buffer>></code></dt>
2023-01-29 15:27:11 +08:00
<dd><p>Create a Certificate Signing Request</p>
</dd>
</dl>
2024-11-14 00:20:17 +08:00
## Functions
<dl>
<dt><a href="#createPrivateKey ">createPrivateKey([size])</a> ⇒ <code>Promise.<buffer></code></dt>
<dd><p>Generate a private RSA key</p>
</dd>
</dl>
2023-01-29 15:27:11 +08:00
<a name="forge"></a>
## forge : <code>object</code>
Legacy node-forge crypto interface
DEPRECATION WARNING: This crypto interface is deprecated and will be removed from acme-client in a future
major release. Please migrate to the new `acme.crypto` interface at your earliest convenience.
**Kind ** : global namespace
<a name="createPublicKey"></a>
2024-11-14 00:20:17 +08:00
## createPublicKey ⇒ <code>Promise.<buffer></code>
2023-01-29 15:27:11 +08:00
Create public key from a private RSA key
2024-11-14 00:20:17 +08:00
**Kind ** : global constant
2023-01-29 15:27:11 +08:00
**Returns ** : <code>Promise.<buffer></code> - PEM encoded public RSA key
| Param | Type | Description |
| --- | --- | --- |
| key | <code>buffer</code> \| <code>string</code> | PEM encoded private RSA key |
**Example **
Create public key
``` js
const publicKey = await acme . forge . createPublicKey ( privateKey ) ;
```
<a name="getPemBody"></a>
2024-11-14 00:20:17 +08:00
## getPemBody ⇒ <code>string</code>
2023-01-29 15:27:11 +08:00
Parse body of PEM encoded object from buffer or string
If multiple objects are chained, the first body will be returned
2024-11-14 00:20:17 +08:00
**Kind ** : global constant
2023-01-29 15:27:11 +08:00
**Returns ** : <code>string</code> - PEM body
| Param | Type | Description |
| --- | --- | --- |
| str | <code>buffer</code> \| <code>string</code> | PEM encoded buffer or string |
<a name="splitPemChain"></a>
2024-11-14 00:20:17 +08:00
## splitPemChain ⇒ <code>Array.<string></code>
2023-01-29 15:27:11 +08:00
Split chain of PEM encoded objects from buffer or string into array
2024-11-14 00:20:17 +08:00
**Kind ** : global constant
2023-01-29 15:27:11 +08:00
**Returns ** : <code>Array.<string></code> - Array of PEM bodies
| Param | Type | Description |
| --- | --- | --- |
| str | <code>buffer</code> \| <code>string</code> | PEM encoded buffer or string |
<a name="getModulus"></a>
2024-11-14 00:20:17 +08:00
## getModulus ⇒ <code>Promise.<buffer></code>
2023-01-29 15:27:11 +08:00
Get modulus
2024-11-14 00:20:17 +08:00
**Kind ** : global constant
2023-01-29 15:27:11 +08:00
**Returns ** : <code>Promise.<buffer></code> - Modulus
| Param | Type | Description |
| --- | --- | --- |
| input | <code>buffer</code> \| <code>string</code> | PEM encoded private key, certificate or CSR |
**Example **
Get modulus
``` js
const m1 = await acme . forge . getModulus ( privateKey ) ;
const m2 = await acme . forge . getModulus ( certificate ) ;
const m3 = await acme . forge . getModulus ( certificateRequest ) ;
```
<a name="getPublicExponent"></a>
2024-11-14 00:20:17 +08:00
## getPublicExponent ⇒ <code>Promise.<buffer></code>
2023-01-29 15:27:11 +08:00
Get public exponent
2024-11-14 00:20:17 +08:00
**Kind ** : global constant
2023-01-29 15:27:11 +08:00
**Returns ** : <code>Promise.<buffer></code> - Exponent
| Param | Type | Description |
| --- | --- | --- |
| input | <code>buffer</code> \| <code>string</code> | PEM encoded private key, certificate or CSR |
**Example **
Get public exponent
``` js
const e1 = await acme . forge . getPublicExponent ( privateKey ) ;
const e2 = await acme . forge . getPublicExponent ( certificate ) ;
const e3 = await acme . forge . getPublicExponent ( certificateRequest ) ;
```
<a name="readCsrDomains"></a>
2024-11-14 00:20:17 +08:00
## readCsrDomains ⇒ <code>Promise.<object></code>
2023-01-29 15:27:11 +08:00
Read domains from a Certificate Signing Request
2024-11-14 00:20:17 +08:00
**Kind ** : global constant
2023-01-29 15:27:11 +08:00
**Returns ** : <code>Promise.<object></code> - {commonName, altNames}
| Param | Type | Description |
| --- | --- | --- |
| csr | <code>buffer</code> \| <code>string</code> | PEM encoded Certificate Signing Request |
**Example **
Read Certificate Signing Request domains
``` js
const { commonName , altNames } = await acme . forge . readCsrDomains ( certificateRequest ) ;
console . log ( ` Common name: ${ commonName } ` ) ;
console . log ( ` Alt names: ${ altNames . join ( ', ' ) } ` ) ;
```
<a name="readCertificateInfo"></a>
2024-11-14 00:20:17 +08:00
## readCertificateInfo ⇒ <code>Promise.<object></code>
2023-01-29 15:27:11 +08:00
Read information from a certificate
2024-11-14 00:20:17 +08:00
**Kind ** : global constant
2023-01-29 15:27:11 +08:00
**Returns ** : <code>Promise.<object></code> - Certificate info
| Param | Type | Description |
| --- | --- | --- |
| cert | <code>buffer</code> \| <code>string</code> | PEM encoded certificate |
**Example **
Read certificate information
``` js
const info = await acme . forge . readCertificateInfo ( certificate ) ;
const { commonName , altNames } = info . domains ;
console . log ( ` Not after: ${ info . notAfter } ` ) ;
console . log ( ` Not before: ${ info . notBefore } ` ) ;
console . log ( ` Common name: ${ commonName } ` ) ;
console . log ( ` Alt names: ${ altNames . join ( ', ' ) } ` ) ;
```
<a name="createCsr"></a>
2024-11-14 00:20:17 +08:00
## createCsr ⇒ <code>Promise.<Array.<buffer>></code>
2023-01-29 15:27:11 +08:00
Create a Certificate Signing Request
2024-11-14 00:20:17 +08:00
**Kind ** : global constant
2023-01-29 15:27:11 +08:00
**Returns ** : <code>Promise.<Array.<buffer>></code> - [privateKey, certificateSigningRequest]
| Param | Type | Description |
| --- | --- | --- |
| data | <code>object</code> | |
| [data.keySize] | <code>number</code> | Size of newly created private key, default: `2048` |
| [data.commonName] | <code>string</code> | |
2024-02-05 19:24:09 +00:00
| [data.altNames] | <code>Array.<string></code> | default: `[]` |
2023-01-29 15:27:11 +08:00
| [data.country] | <code>string</code> | |
| [data.state] | <code>string</code> | |
| [data.locality] | <code>string</code> | |
| [data.organization] | <code>string</code> | |
| [data.organizationUnit] | <code>string</code> | |
| [data.emailAddress] | <code>string</code> | |
| [key] | <code>buffer</code> \| <code>string</code> | CSR private key |
**Example **
Create a Certificate Signing Request
``` js
const [ certificateKey , certificateRequest ] = await acme . forge . createCsr ( {
2024-05-23 19:24:12 +00:00
altNames : [ 'test.example.com' ] ,
2023-01-29 15:27:11 +08:00
} ) ;
```
**Example **
Certificate Signing Request with both common and alternative names
2024-05-23 19:24:12 +00:00
> *Warning*: Certificate subject common name has been [deprecated](https://letsencrypt.org/docs/glossary/#def-CN) and its use is [discouraged](https://cabforum.org/uploads/BRv1.2.3.pdf).
2023-01-29 15:27:11 +08:00
``` js
const [ certificateKey , certificateRequest ] = await acme . forge . createCsr ( {
keySize : 4096 ,
commonName : 'test.example.com' ,
2024-05-23 19:24:12 +00:00
altNames : [ 'foo.example.com' , 'bar.example.com' ] ,
2023-01-29 15:27:11 +08:00
} ) ;
```
**Example **
Certificate Signing Request with additional information
``` js
const [ certificateKey , certificateRequest ] = await acme . forge . createCsr ( {
2024-05-23 19:24:12 +00:00
altNames : [ 'test.example.com' ] ,
2023-01-29 15:27:11 +08:00
country : 'US' ,
state : 'California' ,
locality : 'Los Angeles' ,
organization : 'The Company Inc.' ,
organizationUnit : 'IT Department' ,
2024-05-23 19:24:12 +00:00
emailAddress : 'contact@example.com' ,
2023-01-29 15:27:11 +08:00
} ) ;
```
**Example **
Certificate Signing Request with predefined private key
``` js
const certificateKey = await acme . forge . createPrivateKey ( ) ;
const [ , certificateRequest ] = await acme . forge . createCsr ( {
2024-05-23 19:24:12 +00:00
altNames : [ 'test.example.com' ] ,
2023-01-29 15:27:11 +08:00
} , certificateKey ) ;
2024-11-14 00:20:17 +08:00
< a name = "createPrivateKey" > < / a >
# # createPrivateKey ( [ size ] ) ⇒ < code > Promise . & lt ; buffer & gt ; < / c o d e >
Generate a private RSA key
* * Kind * * : global function
* * Returns * * : < code > Promise . & lt ; buffer & gt ; < / c o d e > - P E M e n c o d e d p r i v a t e R S A k e y
| Param | Type | Description |
| -- - | -- - | -- - |
| [ size ] | < code > number < / c o d e > | S i z e o f t h e k e y , d e f a u l t : ` 2 0 4 8 ` |
* * Example * *
Generate private RSA key
` ` ` js
const privateKey = await acme.forge.createPrivateKey();
```
**Example **
Private RSA key with defined size
``` js
const privateKey = await acme . forge . createPrivateKey ( 4096 ) ;
```