You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: blog/26-04-26/x509-certificates-in-js---encrypt-decrypt-data/x509-certificates-in-js---encrypt-decrypt-data.html
+161-1Lines changed: 161 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -139,6 +139,19 @@ <h4>
139
139
<li>
140
140
node.js supports the entire certificate in pem format
141
141
</li>
142
+
</ul>
143
+
144
+
<p>
145
+
So the rule of thumb:
146
+
</p>
147
+
<ul>
148
+
<li>
149
+
If you want browser compatibility, always use PKCS#8.
150
+
</li>
151
+
<li>
152
+
If you’re in Node, you can use either.
153
+
</li>
154
+
</ul>
142
155
</div>
143
156
144
157
<div>
@@ -182,10 +195,157 @@ <h4>
182
195
183
196
184
197
198
+
<divclass=blog-text>
199
+
<h3class=blog-hdr>
200
+
PKCS#8
201
+
</h3>
202
+
203
+
<p>
204
+
PKCS#8 is a standard format for storing private keys, regardless of the algorithm (RSA, EC, Ed25519, etc.).
205
+
It’s defined in RFC 5208 and RFC 5958.
206
+
<br>
207
+
Think of it as:
208
+
<br>
209
+
A universal container format for private keys.
210
+
<br>
211
+
It wraps the private key with metadata describing:
212
+
</p>
213
+
<ul>
214
+
<li>
215
+
the algorithm (RSA, EC, etc.)
216
+
</li>
217
+
<li>
218
+
parameters (curve, padding, etc.)
219
+
</li>
220
+
<li>
221
+
the key material itself
222
+
</li>
223
+
</ul>
224
+
<p>
225
+
This makes PKCS#8 algorithm‑agnostic, unlike PKCS#1.
226
+
</p>
227
+
</div>
185
228
186
229
230
+
<divclass=blog-text>
231
+
<h3class=blog-hdr>
232
+
PKCS#1 vs PKCS#8 (the important difference)
233
+
</h3>
234
+
235
+
<h4>
236
+
PKCS#1
237
+
</h4>
238
+
<ul>
239
+
<li>
240
+
Only for RSA keys
241
+
</li>
242
+
<li>
243
+
Contains just the RSA private key integers
244
+
</li>
245
+
<li>
246
+
PEM header:
247
+
<code>
248
+
-----BEGIN RSA PRIVATE KEY-----
249
+
</code>
250
+
</li>
251
+
</ul>
252
+
253
+
<h4>
254
+
PKCS#8
255
+
</h4>
256
+
<ul>
257
+
<li>
258
+
Works for any key type (RSA, EC, Ed25519, etc.)
259
+
</li>
260
+
<li>
261
+
Contains:
262
+
<ul>
263
+
<li>
264
+
algorithm identifier
265
+
</li>
266
+
<li>
267
+
private key data
268
+
</li>
269
+
</ul>
270
+
</li>
271
+
<li>
272
+
PEM headers :
273
+
<code>
274
+
-----BEGIN PRIVATE KEY-----
275
+
</code>
276
+
<code>
277
+
-----BEGIN ENCRYPTED PRIVATE KEY-----
278
+
</code>
279
+
</li>
280
+
</ul>
281
+
282
+
<h4>
283
+
Why PKCS#8 is preferred today
284
+
</h4>
285
+
<ul>
286
+
<li>
287
+
It’s universal
288
+
</li>
289
+
<li>
290
+
It’s compatible with modern crypto APIs
291
+
</li>
292
+
<li>
293
+
It supports encryption natively
294
+
</li>
295
+
<li>
296
+
It’s required by WebCrypto
297
+
</li>
298
+
</ul>
299
+
300
+
<h4>
301
+
Why Node.js supports both PKCS#1 and PKCS#8
302
+
</h4>
303
+
<p>
304
+
Node’s crypto module uses OpenSSL, which understands both formats. Node doesn’t care — OpenSSL parses it.
0 commit comments