-
Notifications
You must be signed in to change notification settings - Fork 2
/
rfc7516.xml
3214 lines (2980 loc) · 113 KB
/
rfc7516.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="US-ASCII"?>
<!DOCTYPE rfc SYSTEM "rfc2629.dtd">
<?xml-stylesheet type='text/xsl' href='http://xml2rfc.tools.ietf.org/authoring/rfc2629.xslt' ?>
<?rfc rfcedstyle="yes"?>
<?rfc toc="yes"?>
<?rfc tocompact="yes"?>
<?rfc tocdepth="4"?>
<?rfc tocindent="yes"?>
<?rfc symrefs="yes"?>
<?rfc sortrefs="yes"?>
<?rfc comments="yes"?>
<?rfc inline="yes"?>
<?rfc compact="yes"?>
<?rfc subcompact="no"?>
<rfc category="std" ipr="trust200902" number="7516" submissionType="IETF" consensus="yes">
<front>
<title>JSON Web Encryption (JWE)</title>
<author fullname="Michael B. Jones" initials="M.B." surname="Jones">
<organization>Microsoft</organization>
<address>
<email>[email protected]</email>
<uri>http://self-issued.info/</uri>
</address>
</author>
<author fullname="Joe Hildebrand" initials="J." surname="Hildebrand">
<organization abbrev="Cisco">Cisco Systems, Inc.</organization>
<address>
<email>[email protected]</email>
</address>
</author>
<date month="May" year="2015"/>
<area>Security</area>
<workgroup>JOSE Working Group</workgroup>
<keyword>RFC</keyword>
<keyword>Request for Comments</keyword>
<keyword>I-D</keyword>
<keyword>Internet-Draft</keyword>
<keyword>JavaScript Object Notation</keyword>
<keyword>JSON</keyword>
<keyword>JSON Object Signing and Encryption</keyword>
<keyword>JOSE</keyword>
<keyword>JSON Web Signature</keyword>
<keyword>JWS</keyword>
<keyword>JSON Web Encryption</keyword>
<keyword>JWE</keyword>
<keyword>JSON Web Key</keyword>
<keyword>JWK</keyword>
<keyword>JSON Web Algorithms</keyword>
<keyword>JWA</keyword>
<abstract>
<t>
JSON Web Encryption (JWE) represents encrypted content
using JSON-based data structures.
Cryptographic algorithms and identifiers for use with this
specification are described in the separate
JSON Web Algorithms (JWA) specification
and IANA registries defined by that specification.
Related digital signature and Message Authentication Code (MAC)
capabilities are described
in the separate JSON Web Signature (JWS) specification.
</t>
</abstract>
</front>
<middle>
<section title="Introduction" anchor="Introduction">
<t>
JSON Web Encryption (JWE) represents encrypted content
using JSON-based data structures <xref target="RFC7159"/>.
The JWE cryptographic mechanisms encrypt and provide integrity protection for
an arbitrary sequence of octets.
</t>
<t>
Two closely related serializations for JWEs are defined.
The JWE Compact Serialization is a compact, URL-safe representation
intended for space constrained environments such as HTTP
Authorization headers and URI query parameters.
The JWE JSON Serialization represents JWEs as JSON objects and
enables the same content to be encrypted to multiple parties.
Both share the same cryptographic underpinnings.
</t>
<t>
Cryptographic algorithms and identifiers for use with this
specification are described in the separate
JSON Web Algorithms (JWA) <xref target="JWA" /> specification
and IANA registries defined by that specification.
Related digital signature and MAC capabilities are described
in the separate JSON Web Signature (JWS) <xref target="JWS" />
specification.
</t>
<t>
Names defined by this specification are short because a core goal is
for the resulting representations to be compact.
</t>
<section title="Notational Conventions" anchor="NotationalConventions">
<t>
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL",
"SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY",
and "OPTIONAL" in this document are to be interpreted as
described in
"Key words for use in RFCs to Indicate Requirement Levels" <xref target='RFC2119' />.
The interpretation should only be applied when the terms appear in all capital letters.
</t>
<t>
BASE64URL(OCTETS) denotes the base64url encoding of OCTETS,
per Section 2 of <xref target="JWS" />.
</t>
<t>
UTF8(STRING) denotes the octets of the
UTF-8 <xref target="RFC3629"/> representation of STRING,
where STRING is a sequence of zero or more Unicode <xref target="UNICODE"/> characters.
</t>
<t>
ASCII(STRING) denotes the octets of the
ASCII <xref target="RFC20"/> representation of STRING,
where STRING is a sequence of zero or more ASCII characters.
</t>
<t>
The concatenation of two values A and B
is denoted as A || B.
</t>
</section>
</section>
<section title="Terminology" anchor="Terminology">
<t>
The terms
"JSON Web Signature (JWS)",
"Base64url Encoding",
"Collision-Resistant Name",
"Header Parameter",
"JOSE Header",
and "StringOrURI" are defined by
the JWS specification <xref target="JWS"/>.
</t>
<t>
The terms
"Ciphertext",
"Digital Signature", "Initialization Vector (IV)",
"Message Authentication Code (MAC)",
and "Plaintext" are defined by
the <xref target="RFC4949">"Internet Security Glossary, Version 2"</xref>.
</t>
<t>
These terms are defined by this specification:
</t>
<t>
<list style="hanging">
<t hangText="JSON Web Encryption (JWE)">
<vspace/>
A data structure representing an encrypted and integrity-protected message.
</t>
<t hangText="Authenticated Encryption with Associated Data (AEAD)">
<vspace/>
An AEAD algorithm is one that encrypts the plaintext,
allows Additional Authenticated Data to be specified,
and provides an integrated content integrity check
over the ciphertext and Additional Authenticated Data.
AEAD algorithms accept two inputs, the plaintext and the
Additional Authenticated Data value, and produce two outputs,
the ciphertext and the Authentication Tag value.
AES Galois/Counter Mode (GCM) is one such algorithm.
</t>
<t hangText="Additional Authenticated Data (AAD)">
<vspace/>
An input to an AEAD operation that
is integrity protected but not encrypted.
</t>
<t hangText="Authentication Tag">
<vspace/>
An output of an AEAD operation that
ensures the integrity of
the ciphertext
and the Additional Authenticated Data.
Note that some algorithms may not use an Authentication Tag,
in which case this value is the empty octet sequence.
</t>
<t hangText="Content Encryption Key (CEK)">
<vspace/>
A symmetric key for the AEAD algorithm
used to encrypt the plaintext
to produce the ciphertext and the Authentication Tag.
</t>
<t hangText="JWE Encrypted Key">
<vspace/>
Encrypted Content Encryption Key value.
Note that for some algorithms, the JWE Encrypted Key
value is specified as being the empty octet sequence.
</t>
<t hangText="JWE Initialization Vector">
<vspace/>
Initialization Vector value used
when encrypting the plaintext.
Note that some algorithms may not use an Initialization Vector,
in which case this value is the empty octet sequence.
</t>
<t hangText="JWE AAD">
<vspace/>
Additional value to be integrity protected by
the authenticated encryption operation.
This can only be present when using the JWE JSON Serialization.
(Note that this can also be achieved when using either
the JWE Compact Serialization or the JWE JSON Serialization
by including the AAD value as an integrity-protected Header Parameter value,
but at the cost of the value being double base64url encoded.)
</t>
<t hangText="JWE Ciphertext">
<vspace/>
Ciphertext value resulting from
authenticated encryption of the plaintext with Additional Authenticated Data.
</t>
<t hangText="JWE Authentication Tag">
<vspace/>
Authentication Tag value resulting from
authenticated encryption of the plaintext with Additional Authenticated Data.
</t>
<t hangText="JWE Protected Header">
<vspace/>
JSON object that contains the Header Parameters that
are integrity protected by the authenticated encryption operation.
These parameters apply to all recipients of the JWE.
For the JWE Compact Serialization, this comprises the entire JOSE Header.
For the JWE JSON Serialization, this is one component of the JOSE Header.
</t>
<t hangText="JWE Shared Unprotected Header">
<vspace/>
JSON object that contains the Header Parameters that
apply to all recipients of the JWE
that are not integrity protected.
This can only be present when using the JWE JSON Serialization.
</t>
<t hangText="JWE Per-Recipient Unprotected Header">
<vspace/>
JSON object that contains Header Parameters that
apply to a single recipient of the JWE.
These Header Parameter values are not integrity protected.
This can only be present when using the JWE JSON Serialization.
</t>
<t hangText="JWE Compact Serialization">
<vspace/>
A representation of the JWE as a compact, URL-safe string.
</t>
<t hangText="JWE JSON Serialization">
<vspace/>
A representation of the JWE as a JSON object.
The JWE JSON Serialization
enables the same content to be encrypted to multiple parties.
This representation is neither optimized for compactness nor URL safe.
</t>
<t hangText="Key Management Mode">
<vspace/>
A method of determining the Content Encryption Key value to
use. Each algorithm used for determining the CEK value uses a
specific Key Management Mode.
Key Management Modes employed by this specification are
Key Encryption,
Key Wrapping,
Direct Key Agreement,
Key Agreement with Key Wrapping, and
Direct Encryption.
</t>
<t hangText="Key Encryption">
<vspace/>
A Key Management Mode in which the CEK value
is encrypted to the intended recipient using an asymmetric encryption algorithm.
</t>
<t hangText="Key Wrapping">
<vspace/>
A Key Management Mode in which the CEK value
is encrypted to the intended recipient using a symmetric key wrapping algorithm.
</t>
<t hangText="Direct Key Agreement">
<vspace/>
A Key Management Mode in which a key agreement algorithm is used to agree upon
the CEK value.
</t>
<t hangText="Key Agreement with Key Wrapping">
<vspace/>
A Key Management Mode in which a key agreement algorithm is used to agree upon
a symmetric key used to encrypt the CEK value
to the intended recipient using a symmetric key wrapping algorithm.
</t>
<t hangText="Direct Encryption">
<vspace/>
A Key Management Mode in which the CEK value
used is the secret symmetric key value shared between the parties.
</t>
</list>
</t>
</section>
<section title="JSON Web Encryption (JWE) Overview" anchor="Overview">
<t>
JWE represents encrypted content using JSON data
structures and base64url encoding.
These JSON data structures MAY contain whitespace and/or line breaks
before or after any JSON values or structural characters,
in accordance with Section 2 of <xref target="RFC7159">RFC 7159</xref>.
A JWE represents these logical values
(each of which is defined in <xref target="Terminology"/>):
</t>
<t>
<?rfc subcompact="yes"?>
<list style="symbols">
<t>JOSE Header</t>
<t>JWE Encrypted Key</t>
<t>JWE Initialization Vector</t>
<t>JWE AAD</t>
<t>JWE Ciphertext</t>
<t>JWE Authentication Tag</t>
</list>
<?rfc subcompact="no"?>
</t>
<t>
For a JWE,
the JOSE Header members are the union of the members of these values
(each of which is defined in <xref target="Terminology"/>):
</t>
<t>
<?rfc subcompact="yes"?>
<list style="symbols">
<t>JWE Protected Header</t>
<t>JWE Shared Unprotected Header</t>
<t>JWE Per-Recipient Unprotected Header</t>
</list>
<?rfc subcompact="no"?>
</t>
<t>
JWE utilizes authenticated encryption to ensure the confidentiality
and integrity of the plaintext
and the integrity of the JWE Protected Header and the JWE AAD.
</t>
<t>
This document defines two serializations for JWEs:
a compact, URL-safe serialization called the JWE Compact Serialization
and a JSON serialization called the JWE JSON Serialization.
In both serializations, the
JWE Protected Header,
JWE Encrypted Key,
JWE Initialization Vector,
JWE Ciphertext, and
JWE Authentication Tag
are base64url encoded,
since JSON lacks a way to directly represent arbitrary octet sequences.
When present, the JWE AAD is also base64url encoded.
</t>
<section title="JWE Compact Serialization Overview" anchor="CompactSerializationOverview">
<t>
In the JWE Compact Serialization, no JWE Shared Unprotected Header or
JWE Per-Recipient Unprotected Header are used.
In this case, the JOSE Header and the JWE Protected Header are the same.
</t>
<t>
In the JWE Compact Serialization, a JWE is represented as the
concatenation:
</t>
<t>
<?rfc subcompact="yes"?>
<list style="empty">
<t>BASE64URL(UTF8(JWE Protected Header)) || '.' ||</t>
<t>BASE64URL(JWE Encrypted Key) || '.' ||</t>
<t>BASE64URL(JWE Initialization Vector) || '.' ||</t>
<t>BASE64URL(JWE Ciphertext) || '.' ||</t>
<t>BASE64URL(JWE Authentication Tag)</t>
</list>
<?rfc subcompact="no"?>
</t>
<t>
See <xref target="CompactSerialization"/> for more information
about the JWE Compact Serialization.
</t>
</section>
<section title="JWE JSON Serialization Overview" anchor="JSONSerializationOverview">
<t>
In the JWE JSON Serialization, one or more of the JWE Protected Header,
JWE Shared Unprotected Header, and
JWE Per-Recipient Unprotected Header MUST be present.
In this case, the members of the JOSE Header are the union of
the members of the JWE Protected Header,
JWE Shared Unprotected Header, and
JWE Per-Recipient Unprotected Header
values that are present.
</t>
<t>
In the JWE JSON Serialization, a JWE is represented as a JSON object
containing some or all of these eight members:
<?rfc subcompact="yes"?>
<list style="empty">
<t><spanx style="verb">protected</spanx>, with the value BASE64URL(UTF8(JWE Protected Header))</t>
<t><spanx style="verb">unprotected</spanx>, with the value JWE Shared Unprotected Header</t>
<t><spanx style="verb">header</spanx>, with the value JWE Per-Recipient Unprotected Header</t>
<t><spanx style="verb">encrypted_key</spanx>, with the value BASE64URL(JWE Encrypted Key)</t>
<t><spanx style="verb">iv</spanx>, with the value BASE64URL(JWE Initialization Vector)</t>
<t><spanx style="verb">ciphertext</spanx>, with the value BASE64URL(JWE Ciphertext)</t>
<t><spanx style="verb">tag</spanx>, with the value BASE64URL(JWE Authentication Tag)</t>
<t><spanx style="verb">aad</spanx>, with the value BASE64URL(JWE AAD)</t>
</list>
<?rfc subcompact="no"?>
</t>
<t>
The six base64url-encoded result strings
and the two unprotected JSON object values
are represented as members within a JSON object.
The inclusion of some of these values is OPTIONAL.
The JWE JSON Serialization can also
encrypt the plaintext to multiple recipients.
See <xref target="JSONSerialization"/> for more information
about the JWE JSON Serialization.
</t>
</section>
<section title="Example JWE" anchor="OAEPGCMIntro">
<t>
This example encrypts the plaintext
"The true sign of intelligence is not knowledge but imagination."
to the recipient.
</t>
<t>
The following example JWE Protected Header declares that:
<list style="symbols">
<t>
The Content Encryption Key is encrypted to the recipient
using the RSAES-OAEP <xref target="RFC3447"/> algorithm to produce
the JWE Encrypted Key.
</t>
<t>
Authenticated encryption is performed on the plaintext
using the AES GCM
<xref target="AES"/> <xref target="NIST.800-38D"/>
algorithm with a 256-bit key
to produce the ciphertext and the Authentication Tag.
</t>
</list>
</t>
<figure><artwork><![CDATA[
{"alg":"RSA-OAEP","enc":"A256GCM"}
]]></artwork></figure>
<t>
Encoding this JWE Protected Header as
BASE64URL(UTF8(JWE Protected Header)) gives this value:
</t>
<figure><artwork><![CDATA[
eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkEyNTZHQ00ifQ
]]></artwork></figure>
<t>
The remaining steps to finish creating this JWE are:
<?rfc subcompact="yes"?>
<list style="symbols">
<t>
Generate a random Content Encryption Key (CEK).
</t>
<t>
Encrypt the CEK with the recipient's public key using the RSAES-OAEP
algorithm to produce the JWE Encrypted Key.
</t>
<t>
Base64url-encode the JWE Encrypted Key.
</t>
<t>
Generate a random JWE Initialization Vector.
</t>
<t>
Base64url-encode the JWE Initialization Vector.
</t>
<t>
Let the Additional Authenticated Data encryption parameter be
ASCII(BASE64URL(UTF8(JWE Protected Header))).
</t>
<t>
Perform authenticated encryption on the plaintext
with the AES GCM algorithm
using the CEK as the encryption key,
the JWE Initialization Vector,
and the Additional Authenticated Data value,
requesting a 128-bit Authentication Tag output.
</t>
<t>
Base64url-encode the ciphertext.
</t>
<t>
Base64url-encode the Authentication Tag.
</t>
<t>
Assemble the final representation:
The Compact Serialization of this result is the string
BASE64URL(UTF8(JWE Protected Header))
|| '.' || BASE64URL(JWE Encrypted Key)
|| '.' || BASE64URL(JWE Initialization Vector)
|| '.' || BASE64URL(JWE Ciphertext)
|| '.' || BASE64URL(JWE Authentication Tag).
</t>
</list>
<?rfc subcompact="no"?>
</t>
<t>
The final result in this example
(with line breaks for display purposes only) is:
</t>
<figure><artwork><![CDATA[
eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkEyNTZHQ00ifQ.
OKOawDo13gRp2ojaHV7LFpZcgV7T6DVZKTyKOMTYUmKoTCVJRgckCL9kiMT03JGe
ipsEdY3mx_etLbbWSrFr05kLzcSr4qKAq7YN7e9jwQRb23nfa6c9d-StnImGyFDb
Sv04uVuxIp5Zms1gNxKKK2Da14B8S4rzVRltdYwam_lDp5XnZAYpQdb76FdIKLaV
mqgfwX7XWRxv2322i-vDxRfqNzo_tETKzpVLzfiwQyeyPGLBIO56YJ7eObdv0je8
1860ppamavo35UgoRdbYaBcoh9QcfylQr66oc6vFWXRcZ_ZT2LawVCWTIy3brGPi
6UklfCpIMfIjf7iGdXKHzg.
48V1_ALb6US04U3b.
5eym8TW_c8SuK0ltJ3rpYIzOeDQz7TALvtu6UG9oMo4vpzs9tX_EFShS8iB7j6ji
SdiwkIr3ajwQzaBtQD_A.
XFBoMYUZodetZdvTiFvSkQ
]]></artwork></figure>
<t>
See <xref target="OAEPGCMExample"/> for the complete details of computing this JWE.
See <xref target="JWEExamples"/> for additional examples,
including examples using the JWE JSON Serialization
in Sections <xref target="JSONSerializationExample" format="counter"/>
and <xref target="FlattenedJSONSerializationExample" format="counter"/>.
</t>
</section>
</section>
<section title="JOSE Header" anchor="Header">
<t>
For a JWE,
the members of the JSON object(s) representing the JOSE Header
describe the encryption applied to the plaintext and optionally
additional properties of the JWE.
The Header Parameter names within the JOSE Header MUST be unique,
just as described in Section 4 of <xref target="JWS"/>.
The rules about handling Header Parameters that are not understood
by the implementation are also the same.
The classes of Header Parameter names are likewise the same.
</t>
<section title="Registered Header Parameter Names" anchor="RegisteredHeaderParameterName">
<t>
The following Header Parameter names for use in JWEs are registered
in the IANA
"JSON Web Signature and Encryption Header Parameters" registry
established by
<xref target="JWS"/>,
with meanings as defined below.
</t>
<t>
As indicated by the common registry, JWSs and JWEs share a
common Header Parameter space; when a parameter is used by
both specifications, its usage must be compatible
between the specifications.
</t>
<section title='"alg" (Algorithm) Header Parameter' anchor="algDef">
<t>
This parameter has the same meaning, syntax, and processing rules as the
<spanx style="verb">alg</spanx> Header Parameter defined in
Section 4.1.1 of <xref target="JWS" />, except that
the Header Parameter identifies the cryptographic algorithm used to
encrypt or determine the value of the CEK.
The encrypted content is not usable if the <spanx style="verb">alg</spanx>
value does not represent a supported algorithm, or if the recipient does
not have a key that can be used with that algorithm.
</t>
<t>
A list of defined <spanx style="verb">alg</spanx> values
for this use can be found
in the IANA "JSON Web Signature and Encryption Algorithms" registry
established by
<xref target="JWA"/>;
the initial contents of this registry are the values defined in
Section 4.1 of
<xref target="JWA"/>.
</t>
</section>
<section title='"enc" (Encryption Algorithm) Header Parameter' anchor="encDef">
<t>
The <spanx style="verb">enc</spanx> (encryption algorithm)
Header Parameter identifies the content encryption algorithm
used to perform authenticated encryption on the plaintext
to produce the ciphertext and the Authentication Tag.
This algorithm MUST be an AEAD algorithm with a specified key length.
The encrypted content is not usable if the <spanx style="verb">enc</spanx>
value does not represent a supported algorithm.
<spanx style="verb">enc</spanx> values should either be
registered in the IANA
"JSON Web Signature and Encryption Algorithms" registry
established by
<xref target="JWA" /> or be
a value that contains a Collision-Resistant Name.
The <spanx style="verb">enc</spanx> value is a case-sensitive ASCII string
containing a StringOrURI value.
This Header Parameter MUST be present
and MUST be understood and processed by implementations.
</t>
<t>
A list of defined <spanx style="verb">enc</spanx> values
for this use can be found
in the IANA "JSON Web Signature and Encryption Algorithms" registry
established by
<xref target="JWA"/>;
the initial contents of this registry are the values defined in
Section 5.1 of
<xref target="JWA"/>.
</t>
</section>
<section title='"zip" (Compression Algorithm) Header Parameter' anchor="zipDef">
<t>
The <spanx style="verb">zip</spanx> (compression algorithm)
applied to the plaintext before encryption, if any.
The <spanx style="verb">zip</spanx> value defined by this specification is:
</t>
<t>
<?rfc subcompact="yes"?>
<list style='symbols'>
<t>
<spanx style="verb">DEF</spanx>
- Compression with the DEFLATE <xref target="RFC1951" /> algorithm
</t>
</list>
<?rfc subcompact="no"?>
</t>
<t>
Other values MAY be used.
Compression algorithm values can be registered in the IANA
"JSON Web Encryption Compression Algorithms" registry
established by
<xref target="JWA"/>.
The <spanx style="verb">zip</spanx> value is a case-sensitive string.
If no <spanx style="verb">zip</spanx> parameter is present,
no compression is applied to the plaintext before encryption.
When used, this Header Parameter MUST be integrity protected;
therefore, it MUST occur only within the JWE Protected Header.
Use of this Header Parameter is OPTIONAL.
This Header Parameter MUST be understood and processed by implementations.
</t>
</section>
<section title='"jku" (JWK Set URL) Header Parameter' anchor="jkuDef">
<t>
This parameter has the same meaning, syntax, and processing rules as the
<spanx style="verb">jku</spanx> Header Parameter defined in
Section 4.1.2 of <xref target="JWS" />, except that
the JWK Set resource contains
the public key to which the JWE was encrypted;
this can be used to determine the private key needed to decrypt the JWE.
</t>
</section>
<section title='"jwk" (JSON Web Key) Header Parameter' anchor="jwkDef">
<t>
This parameter has the same meaning, syntax, and processing rules as the
<spanx style="verb">jwk</spanx> Header Parameter defined in
Section 4.1.3 of <xref target="JWS" />, except that
the key is
the public key to which the JWE was encrypted;
this can be used to determine the private key needed to decrypt the JWE.
</t>
</section>
<section title='"kid" (Key ID) Header Parameter' anchor="kidDef">
<t>
This parameter has the same meaning, syntax, and processing rules as the
<spanx style="verb">kid</spanx> Header Parameter defined in
Section 4.1.4 of <xref target="JWS" />, except that
the key hint references
the public key to which the JWE was encrypted;
this can be used to determine the private key needed to decrypt the JWE.
This parameter allows originators to explicitly signal a change of
key to JWE recipients.
</t>
</section>
<section title='"x5u" (X.509 URL) Header Parameter' anchor="x5uDef">
<t>
This parameter has the same meaning, syntax, and processing rules as the
<spanx style="verb">x5u</spanx> Header Parameter defined in
Section 4.1.5 of <xref target="JWS" />, except that
the X.509 public key certificate or certificate chain
<xref target="RFC5280"/> contains the public key
to which the JWE was encrypted;
this can be used to determine the private key needed to decrypt the JWE.
</t>
</section>
<section title='"x5c" (X.509 Certificate Chain) Header Parameter' anchor="x5cDef">
<t>
This parameter has the same meaning, syntax, and processing rules as the
<spanx style="verb">x5c</spanx> Header Parameter defined in
Section 4.1.6 of <xref target="JWS" />, except that
the X.509 public key certificate or certificate chain
<xref target="RFC5280"/> contains the public key
to which the JWE was encrypted;
this can be used to determine the private key needed to decrypt the JWE.
</t>
<t>
See Appendix B of <xref target="JWS"/> for an example
<spanx style="verb">x5c</spanx> value.
</t>
</section>
<section title='"x5t" (X.509 Certificate SHA-1 Thumbprint) Header Parameter' anchor="x5tDef">
<t>
This parameter has the same meaning, syntax, and processing rules as the
<spanx style="verb">x5t</spanx> Header Parameter defined in
Section 4.1.7 of <xref target="JWS" />, except that
the certificate referenced by the thumbprint contains
the public key to which the JWE was encrypted;
this can be used to determine the private key needed to decrypt the JWE.
Note that certificate thumbprints are also sometimes known as certificate fingerprints.
</t>
</section>
<section title='"x5t#S256" (X.509 Certificate SHA-256 Thumbprint) Header Parameter' anchor="x5tS256Def">
<t>
This parameter has the same meaning, syntax, and processing rules as the
<spanx style="verb">x5t#S256</spanx> Header Parameter defined in
Section 4.1.8 of <xref target="JWS" />, except that
the certificate referenced by the thumbprint contains
the public key to which the JWE was encrypted;
this can be used to determine the private key needed to decrypt the JWE.
Note that certificate thumbprints are also sometimes known as certificate fingerprints.
</t>
</section>
<section title='"typ" (Type) Header Parameter' anchor="typDef">
<t>
This parameter has the same meaning, syntax, and processing rules as the
<spanx style="verb">typ</spanx> Header Parameter defined in
Section 4.1.9 of <xref target="JWS" />, except that
the type is that of this complete JWE.
</t>
</section>
<section title='"cty" (Content Type) Header Parameter' anchor="ctyDef">
<t>
This parameter has the same meaning, syntax, and processing rules as the
<spanx style="verb">cty</spanx> Header Parameter defined in
Section 4.1.10 of <xref target="JWS" />, except that
the type is that of the secured content (the plaintext).
</t>
</section>
<section title='"crit" (Critical) Header Parameter' anchor="critDef">
<t>
This parameter has the same meaning, syntax, and processing rules as the
<spanx style="verb">crit</spanx> Header Parameter defined in
Section 4.1.11 of <xref target="JWS" />, except that
Header Parameters for a JWE are being referred to,
rather than Header Parameters for a JWS.
</t>
</section>
</section>
<section title="Public Header Parameter Names" anchor="PublicHeaderParameterName">
<t>
Additional Header Parameter names can be defined by those
using JWEs. However, in order to prevent collisions, any new
Header Parameter name should either be registered in the IANA
"JSON Web Signature and Encryption Header Parameters" registry
established by
<xref target="JWS" /> or be a Public Name:
a value that contains a Collision-Resistant Name.
In each case, the definer of the name
or value needs to take reasonable precautions to make sure they
are in control of the part of the namespace they use to
define the Header Parameter name.
</t>
<t>
New Header Parameters should be introduced sparingly, as
they can result in non-interoperable JWEs.
</t>
</section>
<section title="Private Header Parameter Names" anchor="PrivateHeaderParameterName">
<t>
A producer and consumer of a JWE may agree to use Header Parameter names
that are Private Names: names that are
not Registered Header Parameter names (<xref target="RegisteredHeaderParameterName"/>)
or Public Header Parameter names (<xref target="PublicHeaderParameterName"/>).
Unlike Public Header Parameter names,
Private Header Parameter names are subject to collision and
should be used with caution.
</t>
</section>
</section>
<section title="Producing and Consuming JWEs" anchor="JWERules">
<section title="Message Encryption" anchor="Encryption">
<t>
The message encryption process is as follows.
The order of the steps is not significant in cases where
there are no dependencies between the inputs and outputs of the steps.
</t>
<t>
<list style="numbers">
<t>
Determine the Key Management Mode employed by the algorithm
used to determine the Content Encryption Key value.
(This is the algorithm recorded in the
<spanx style="verb">alg</spanx> (algorithm)
Header Parameter of the resulting JWE.)
</t>
<t>
When Key Wrapping, Key Encryption,
or Key Agreement with Key Wrapping are employed,
generate a random CEK value.
See <xref target="RFC4086">RFC 4086</xref> for
considerations on generating random values.
The CEK MUST have a length equal to that
required for the content encryption algorithm.
</t>
<t>
When Direct Key Agreement or Key Agreement with Key Wrapping
are employed, use the key agreement algorithm
to compute the value of the agreed upon key.
When Direct Key Agreement is employed,
let the CEK be the agreed upon key.
When Key Agreement with Key Wrapping is employed,
the agreed upon key will be used to wrap the CEK.
</t>
<t>
When Key Wrapping, Key Encryption,
or Key Agreement with Key Wrapping are employed,
encrypt the CEK to the recipient and let the result be the
JWE Encrypted Key.
</t>
<t>
When Direct Key Agreement or Direct Encryption are employed,
let the JWE Encrypted Key be the empty octet sequence.
</t>
<t>
When Direct Encryption is employed,
let the CEK be the shared symmetric key.
</t>
<t>
Compute the encoded key value BASE64URL(JWE Encrypted Key).
</t>
<t>
If the JWE JSON Serialization is being used, repeat this process
(steps 1-7)
for each recipient.
</t>
<t>
Generate a random JWE Initialization Vector of the correct size
for the content encryption algorithm (if required for the algorithm);
otherwise, let the JWE Initialization Vector be the empty octet sequence.
</t>
<t>
Compute the encoded Initialization Vector value
BASE64URL(JWE Initialization Vector).
</t>
<t>
If a <spanx style="verb">zip</spanx> parameter was included,
compress the plaintext using the specified compression algorithm
and let M be the octet sequence representing the compressed plaintext;
otherwise, let M be the octet sequence representing the plaintext.
</t>
<t>
Create the JSON object(s) containing the desired set of Header Parameters,
which together comprise the JOSE Header: one or more of the JWE Protected
Header, the JWE Shared Unprotected
Header, and the JWE Per-Recipient Unprotected Header.
</t>
<t>
Compute the Encoded Protected Header value
BASE64URL(UTF8(JWE Protected Header)).
If the JWE Protected Header is not present
(which can only happen when using the JWE JSON Serialization
and no <spanx style="verb">protected</spanx> member is present),
let this value be the empty string.
</t>
<t>
Let the Additional Authenticated Data encryption parameter be
ASCII(Encoded Protected Header).
However, if a JWE AAD value is present
(which can only be the case when using the JWE JSON Serialization),
instead let the Additional Authenticated Data encryption parameter be
ASCII(Encoded Protected Header || '.' || BASE64URL(JWE AAD)).
</t>
<t>
Encrypt M using the CEK, the JWE Initialization Vector, and
the Additional Authenticated Data value
using the specified content encryption algorithm
to create the JWE Ciphertext value and the JWE Authentication Tag
(which is the Authentication Tag output from the encryption operation).
</t>
<t>
Compute the encoded ciphertext value BASE64URL(JWE Ciphertext).
</t>
<t>
Compute the encoded Authentication Tag value
BASE64URL(JWE Authentication Tag).
</t>
<t>
If a JWE AAD value is present,
compute the encoded AAD value BASE64URL(JWE AAD).
</t>
<t>
Create the desired serialized output.
The Compact Serialization of this result is the string
BASE64URL(UTF8(JWE Protected Header))
|| '.' || BASE64URL(JWE Encrypted Key)
|| '.' || BASE64URL(JWE Initialization Vector)
|| '.' || BASE64URL(JWE Ciphertext)
|| '.' || BASE64URL(JWE Authentication Tag).
The JWE JSON Serialization is described in <xref target="JSONSerialization"/>.
</t>
</list>
</t>
</section>
<section title="Message Decryption" anchor="Decryption">
<t>
The message decryption process is the reverse of the
encryption process.
The order of the steps is not significant in cases where
there are no dependencies between the inputs and outputs of the steps.
If any of these steps fail, the encrypted content cannot be validated.
</t>
<t>
When there are multiple recipients,
it is an application decision which of the recipients' encrypted content
must successfully validate for the JWE to be accepted.
In some cases, encrypted content for all recipients must successfully validate
or the JWE will be considered invalid.
In other cases, only the encrypted content for a single recipient
needs to be successfully validated.
However, in all cases, the encrypted content for at least one recipient
MUST successfully validate or the JWE MUST be considered invalid.
</t>
<t>
<list style="numbers">
<t>
Parse the JWE representation to extract the serialized values
for the components of the JWE.
When using the JWE Compact Serialization,
these components are
the base64url-encoded representations of
the JWE Protected Header,
the JWE Encrypted Key,
the JWE Initialization Vector,
the JWE Ciphertext, and
the JWE Authentication Tag,
and when using the JWE JSON Serialization,
these components also include the base64url-encoded representation of
the JWE AAD and the unencoded
JWE Shared Unprotected Header and
JWE Per-Recipient Unprotected Header values.