Skip to content

Commit 5f1a7ac

Browse files
committed
Doc: fix code blocks to render as blocks consistently
1 parent 2715a3e commit 5f1a7ac

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

README.md

+29
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,13 @@ Processing a JWE or JWS relies on a KeyStore.
6767

6868
### Obtaining a KeyStore ###
6969
To create an empty keystore:
70+
7071
```
7172
keystore = jose.JWK.createKeyStore();
7273
```
7374

7475
To import a JWK-set as a keystore:
76+
7577
```
7678
// {input} is a String or JSON object representing the JWK-set
7779
jose.JWK.asKeyStore(input).
@@ -84,18 +86,21 @@ jose.JWK.asKeyStore(input).
8486
### Exporting a KeyStore ###
8587

8688
To export the public keys of a keystore as a JWK-set:
89+
8790
```
8891
output = keystore.toJSON();
8992
```
9093

9194
To export **all** the keys of a keystore:
95+
9296
```
9397
output = keystore.toJSON(true);
9498
```
9599

96100
### Retrieving Keys ###
97101

98102
To retrieve a key from a keystore:
103+
99104
```
100105
// by 'kid'
101106
key = keystore.get(kid);
@@ -123,11 +128,13 @@ key = keystore.get({ kid: kid, kty: 'RSA', use: 'enc' });
123128
### Searching for Keys ###
124129

125130
To retrieve all the keys from a keystore:
131+
126132
```
127133
everything = keystore.all();
128134
```
129135

130136
`all()` can be filtered much like `get()`:
137+
131138
```
132139
// filter by 'kid'
133140
everything = keystore.all({ kid: kid });
@@ -148,6 +155,7 @@ everything = keystore.all({ kid: kid, kty: 'RSA', alg: 'RSA-OAEP' });
148155
### Managing Keys ###
149156

150157
To import an existing Key (as a JSON object or Key instance):
158+
151159
```
152160
// input is either a:
153161
// * jose.JWK.Key to copy from; or
@@ -161,6 +169,7 @@ keystore.add(input).
161169
```
162170

163171
To generate a new Key:
172+
164173
```
165174
// first argument is the key type (kty)
166175
// second is the key size (in bits) or named curve ('crv') for "EC"
@@ -192,6 +201,7 @@ kestyore.remove(key);
192201
### Importing and Exporting a Single Key ###
193202

194203
To import a single Key (as a JSON Object, or String serialized JSON Object):
204+
195205
```
196206
jose.JWK.asKey(input).
197207
then(function(result) {
@@ -215,6 +225,7 @@ var output = key.toJSON(true);
215225
### Signing Content ###
216226

217227
At its simplest, to create a JWS:
228+
218229
```
219230
// {input} is a Buffer
220231
jose.JWS.createSign(key).
@@ -228,6 +239,7 @@ jose.JWS.createSign(key).
228239
The JWS is signed using the preferred algorithm appropriate for the given Key. The preferred algorithm is the first item returned by `key.algorithms("sign")`.
229240

230241
To create a JWS using another serialization format:
242+
231243
```
232244
jose.JWS.createSign({ format: 'flattened' }, key).
233245
update(input).
@@ -255,6 +267,7 @@ jose.JWS.createSign({ alg: 'PS256' }, key).
255267
```
256268

257269
To create a JWS for a specified content type:
270+
258271
```
259272
jose.JWS.createSign({ fields: { cty: 'jwk+json' } }, key).
260273
update(input).
@@ -265,6 +278,7 @@ jose.JWS.createSign({ fields: { cty: 'jwk+json' } }, key).
265278
```
266279

267280
To create a JWS from String content:
281+
268282
```
269283
jose.JWS.createSign(key).
270284
update(input, "utf8").
@@ -275,6 +289,7 @@ jose.JWS.createSign(key).
275289
```
276290

277291
To create a JWS with multiple signatures:
292+
278293
```
279294
// {keys} is an Array of jose.JWK.Key instances
280295
jose.JWS.createSign(keys).
@@ -288,6 +303,7 @@ jose.JWS.createSign(keys).
288303
### Verifying a JWS ###
289304

290305
To verify a JWS, and retrieve the payload:
306+
291307
```
292308
jose.JWS.createVerify(keystore).
293309
verify(input).
@@ -300,6 +316,7 @@ jose.JWS.createVerify(keystore).
300316
```
301317

302318
To verify using an implied Key:
319+
303320
```
304321
// {key} can be:
305322
// * jose.JWK.Key
@@ -316,6 +333,7 @@ jose.JWS.createVerify(key).
316333
### Encrypting Content ###
317334

318335
At its simplest, to create a JWE:
336+
319337
```
320338
// {input} is a Buffer
321339
jose.JWE.createEncrypt(key).
@@ -333,6 +351,7 @@ How the JWE content is encrypted depends on the provided Key.
333351

334352

335353
To create a JWE using a different serialization format:
354+
336355
```
337356
jose.JWE.createEncrypt({ format: 'compact' }, key).
338357
update(input).
@@ -350,6 +369,7 @@ jose.JWE.createEncrypt({ format: 'flattened' }, key).
350369
```
351370

352371
To create a JWE and compressing the content before encrypting:
372+
353373
```
354374
jose.JWE.createEncrypt({ zip: true }, key).
355375
update(input).
@@ -360,6 +380,7 @@ jose.JWE.createEncrypt({ zip: true }, key).
360380
```
361381

362382
To create a JWE for a specific content type:
383+
363384
```
364385
jose.JWE.createEncrypt({ fields: { cty : 'jwk+json' } }, key).
365386
update(input).
@@ -370,6 +391,7 @@ jose.JWE.createEncrypt({ fields: { cty : 'jwk+json' } }, key).
370391
```
371392

372393
To create a JWE with multiple recipients:
394+
373395
```
374396
// {keys} is an Array of jose.JWK.Key instances
375397
jose.JWE.createEncrypt(keys).
@@ -383,6 +405,7 @@ jose.JWE.createEncrypt(keys).
383405
### Decrypting a JWE ###
384406

385407
To decrypt a JWE, and retrieve the plaintext:
408+
386409
```
387410
jose.JWE.createDecrypt(keystore).
388411
verify(input).
@@ -395,6 +418,7 @@ jose.JWE.createDecrypt(keystore).
395418
```
396419

397420
To decrypt a JWE using an implied key:
421+
398422
```
399423
jose.JWE.createDecrypt(key).
400424
verify(input).
@@ -408,18 +432,21 @@ jose.JWE.createDecrypt(key).
408432
### Converting to Buffer ###
409433

410434
To convert a [Typed Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays), [ArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer), or Array of Numbers to a Buffer:
435+
411436
```
412437
buff = jose.util.asBuffer(input);
413438
```
414439

415440
### URI-Safe Base64 ###
416441

417442
To convert from a Buffer to a base64uri-encoded String:
443+
418444
```
419445
var output = jose.util.base64url.encode(input);
420446
```
421447

422448
To convert a String to a base64uri-encoded String:
449+
423450
```
424451
// explicit encoding
425452
output = jose.util.base64url.encode(input, "utf8");
@@ -429,11 +456,13 @@ output = jose.util.base64url.encode(input);
429456
```
430457

431458
To convert a base64uri-encoded String to a Buffer:
459+
432460
```
433461
var output = jose.util.base64url.decode(input);
434462
```
435463

436464
To convert a base64uri-encoded String to a String:
465+
437466
```
438467
output = jose.util.base64url.decode(input, "utf8");
439468
```

0 commit comments

Comments
 (0)