@@ -48,7 +48,60 @@ The `crypto` module provides the `Certificate` class for working with SPKAC
48
48
data. The most common usage is handling output generated by the HTML5
49
49
` <keygen> ` element. Node.js uses [ OpenSSL's SPKAC implementation] [ ] internally.
50
50
51
- ### new crypto.Certificate()
51
+ ### Certificate.exportChallenge(spkac)
52
+ <!-- YAML
53
+ added: REPLACEME
54
+ -->
55
+ - ` spkac ` {string | Buffer | TypedArray | DataView}
56
+ - Returns {Buffer} The challenge component of the ` spkac ` data structure, which
57
+ includes a public key and a challenge.
58
+
59
+ ``` js
60
+ const { Certificate } = require (' crypto' );
61
+ const spkac = getSpkacSomehow ();
62
+ const challenge = Certificate .exportChallenge (spkac);
63
+ console .log (challenge .toString (' utf8' ));
64
+ // Prints: the challenge as a UTF8 string
65
+ ```
66
+
67
+ ### Certificate.exportPublicKey(spkac)
68
+ <!-- YAML
69
+ added: REPLACEME
70
+ -->
71
+ - ` spkac ` {string | Buffer | TypedArray | DataView}
72
+ - Returns {Buffer} The public key component of the ` spkac ` data structure,
73
+ which includes a public key and a challenge.
74
+
75
+ ``` js
76
+ const { Certificate } = require (' crypto' );
77
+ const spkac = getSpkacSomehow ();
78
+ const publicKey = Certificate .exportPublicKey (spkac);
79
+ console .log (publicKey);
80
+ // Prints: the public key as <Buffer ...>
81
+ ```
82
+
83
+ ### Certificate.verifySpkac(spkac)
84
+ <!-- YAML
85
+ added: REPLACEME
86
+ -->
87
+ - ` spkac ` {Buffer | TypedArray | DataView}
88
+ - Returns {boolean} ` true ` if the given ` spkac ` data structure is valid, ` false `
89
+ otherwise.
90
+
91
+ ``` js
92
+ const { Certificate } = require (' crypto' );
93
+ const spkac = getSpkacSomehow ();
94
+ console .log (Certificate .verifySpkac (Buffer .from (spkac)));
95
+ // Prints: true or false
96
+ ```
97
+
98
+ ### Legacy API
99
+
100
+ As a still supported legacy interface, it is possible (but not recommended) to
101
+ create new instances of the ` crypto.Certificate ` class as illustrated in the
102
+ examples below.
103
+
104
+ #### new crypto.Certificate()
52
105
53
106
Instances of the ` Certificate ` class can be created using the ` new ` keyword
54
107
or by calling ` crypto.Certificate() ` as a function:
@@ -60,7 +113,7 @@ const cert1 = new crypto.Certificate();
60
113
const cert2 = crypto .Certificate ();
61
114
```
62
115
63
- ### certificate.exportChallenge(spkac)
116
+ #### certificate.exportChallenge(spkac)
64
117
<!-- YAML
65
118
added: v0.11.8
66
119
-->
@@ -76,7 +129,7 @@ console.log(challenge.toString('utf8'));
76
129
// Prints: the challenge as a UTF8 string
77
130
```
78
131
79
- ### certificate.exportPublicKey(spkac)
132
+ #### certificate.exportPublicKey(spkac)
80
133
<!-- YAML
81
134
added: v0.11.8
82
135
-->
@@ -92,7 +145,7 @@ console.log(publicKey);
92
145
// Prints: the public key as <Buffer ...>
93
146
```
94
147
95
- ### certificate.verifySpkac(spkac)
148
+ #### certificate.verifySpkac(spkac)
96
149
<!-- YAML
97
150
added: v0.11.8
98
151
-->
@@ -1747,9 +1800,13 @@ negative performance implications for some applications, see the
1747
1800
### crypto.randomFillSync(buffer[ , offset] [ , size ] )
1748
1801
<!-- YAML
1749
1802
added: v7.10.0
1803
+ changes:
1804
+ - version: REPLACEME
1805
+ pr-url: https://github.com/nodejs/node/pull/15231
1806
+ description: The `buffer` argument may be any ArrayBufferView
1750
1807
-->
1751
1808
1752
- * ` buffer ` {Buffer|Uint8Array} Must be supplied.
1809
+ * ` buffer ` {Buffer|Uint8Array|ArrayBufferView } Must be supplied.
1753
1810
* ` offset ` {number} Defaults to ` 0 ` .
1754
1811
* ` size ` {number} Defaults to ` buffer.length - offset ` .
1755
1812
@@ -1769,12 +1826,29 @@ crypto.randomFillSync(buf, 5, 5);
1769
1826
console .log (buf .toString (' hex' ));
1770
1827
```
1771
1828
1829
+ Any ` TypedArray ` or ` DataView ` instance may be passed as ` buffer ` .
1830
+
1831
+ ``` js
1832
+ const a = new Uint32Array (10 );
1833
+ console .log (crypto .randomFillSync (a).toString (' hex' ));
1834
+
1835
+ const b = new Float64Array (10 );
1836
+ console .log (crypto .randomFillSync (a).toString (' hex' ));
1837
+
1838
+ const c = new DataView (new ArrayBuffer (10 ));
1839
+ console .log (crypto .randomFillSync (a).toString (' hex' ));
1840
+ ```
1841
+
1772
1842
### crypto.randomFill(buffer[ , offset] [ , size ] , callback)
1773
1843
<!-- YAML
1774
1844
added: v7.10.0
1845
+ changes:
1846
+ - version: REPLACEME
1847
+ pr-url: https://github.com/nodejs/node/pull/15231
1848
+ description: The `buffer` argument may be any ArrayBufferView
1775
1849
-->
1776
1850
1777
- * ` buffer ` {Buffer|Uint8Array} Must be supplied.
1851
+ * ` buffer ` {Buffer|Uint8Array|ArrayBufferView } Must be supplied.
1778
1852
* ` offset ` {number} Defaults to ` 0 ` .
1779
1853
* ` size ` {number} Defaults to ` buffer.length - offset ` .
1780
1854
* ` callback ` {Function} ` function(err, buf) {} ` .
@@ -1804,6 +1878,28 @@ crypto.randomFill(buf, 5, 5, (err, buf) => {
1804
1878
});
1805
1879
```
1806
1880
1881
+ Any ` TypedArray ` or ` DataView ` instance may be passed as ` buffer ` .
1882
+
1883
+ ``` js
1884
+ const a = new Uint32Array (10 );
1885
+ crypto .randomFill (a, (err , buf ) => {
1886
+ if (err) throw err;
1887
+ console .log (buf .toString (' hex' ));
1888
+ });
1889
+
1890
+ const b = new Float64Array (10 );
1891
+ crypto .randomFill (b, (err , buf ) => {
1892
+ if (err) throw err;
1893
+ console .log (buf .toString (' hex' ));
1894
+ });
1895
+
1896
+ const c = new DataView (new ArrayBuffer (10 ));
1897
+ crypto .randomFill (c, (err , buf ) => {
1898
+ if (err) throw err;
1899
+ console .log (buf .toString (' hex' ));
1900
+ });
1901
+ ```
1902
+
1807
1903
Note that this API uses libuv's threadpool, which can have surprising and
1808
1904
negative performance implications for some applications, see the
1809
1905
[ ` UV_THREADPOOL_SIZE ` ] [ ] documentation for more information.
0 commit comments