Skip to content

Commit dfcd972

Browse files
committed
Migrated all uses of Jwts.KEY to Jwe.enc
1 parent 2f400ff commit dfcd972

25 files changed

+838
-148
lines changed

README.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2370,7 +2370,7 @@ Content Encryption Key (CEK):
23702370
| PBES2 with HMAC SHA-512 and "A256KW" wrapping
23712371
|===
23722372

2373-
These are all represented as constants in the `io.jsonwebtoken.Jwts.KEY` registry singleton as
2373+
These are all represented as constants in the `io.jsonwebtoken.Jwe.enc` registry singleton as
23742374
implementations of the `io.jsonwebtoken.security.KeyAlgorithm` interface.
23752375

23762376
But 17 algorithms are a lot to choose from. When would you use them? The sections below describe when you might

api/src/main/java/io/jsonwebtoken/Header.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public interface Header extends Map<String, Object> {
137137
* identifies the cryptographic key management algorithm used to encrypt or determine the value of the Content
138138
* Encryption Key (CEK). The encrypted content is not usable if the <code>alg</code> value does not represent a
139139
* supported algorithm, or if the recipient does not have a key that can be used with that algorithm. Consider
140-
* using {@link Jwts.KEY}.{@link io.jsonwebtoken.lang.Registry#get(Object) get(id)} to convert this string value
140+
* using {@link Jwe.enc}.{@link io.jsonwebtoken.lang.Registry#get(Object) get(id)} to convert this string value
141141
* to a type-safe {@link io.jsonwebtoken.security.KeyAlgorithm KeyAlgorithm} instance.</li>
142142
* </ul>
143143
*

api/src/main/java/io/jsonwebtoken/Jwe.java

Lines changed: 634 additions & 0 deletions
Large diffs are not rendered by default.

api/src/main/java/io/jsonwebtoken/JweHeader.java

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ public interface JweHeader extends ProtectedHeader {
6565
* @return the <a href="https://www.rfc-editor.org/rfc/rfc7518.html#section-4.6.1.1">{@code epk} (Ephemeral
6666
* Public Key)</a> header value created by the JWE originator for use with key agreement algorithms, or
6767
* {@code null} if not present.
68-
* @see Jwts.KEY
69-
* @see Jwts.KEY#ECDH_ES
70-
* @see Jwts.KEY#ECDH_ES_A128KW
71-
* @see Jwts.KEY#ECDH_ES_A192KW
72-
* @see Jwts.KEY#ECDH_ES_A256KW
68+
* @see Jwe.enc
69+
* @see Jwe.enc#ECDH_ES
70+
* @see Jwe.enc#ECDH_ES_A128KW
71+
* @see Jwe.enc#ECDH_ES_A192KW
72+
* @see Jwe.enc#ECDH_ES_A256KW
7373
*/
7474
PublicJwk<?> getEphemeralPublicKey();
7575

@@ -80,10 +80,10 @@ public interface JweHeader extends ProtectedHeader {
8080
* @return any information about the JWE producer for use with key agreement algorithms, or {@code null} if not
8181
* present.
8282
* @see <a href="https://www.rfc-editor.org/rfc/rfc7518.html#section-4.6.1.2">JWE <code>apu</code> (Agreement PartyUInfo) Header Parameter</a>
83-
* @see Jwts.KEY#ECDH_ES
84-
* @see Jwts.KEY#ECDH_ES_A128KW
85-
* @see Jwts.KEY#ECDH_ES_A192KW
86-
* @see Jwts.KEY#ECDH_ES_A256KW
83+
* @see Jwe.enc#ECDH_ES
84+
* @see Jwe.enc#ECDH_ES_A128KW
85+
* @see Jwe.enc#ECDH_ES_A192KW
86+
* @see Jwe.enc#ECDH_ES_A256KW
8787
*/
8888
byte[] getAgreementPartyUInfo();
8989

@@ -94,10 +94,10 @@ public interface JweHeader extends ProtectedHeader {
9494
* @return any information about the JWE recipient for use with key agreement algorithms, or {@code null} if not
9595
* present.
9696
* @see <a href="https://www.rfc-editor.org/rfc/rfc7518.html#section-4.6.1.3">JWE <code>apv</code> (Agreement PartyVInfo) Header Parameter</a>
97-
* @see Jwts.KEY#ECDH_ES
98-
* @see Jwts.KEY#ECDH_ES_A128KW
99-
* @see Jwts.KEY#ECDH_ES_A192KW
100-
* @see Jwts.KEY#ECDH_ES_A256KW
97+
* @see Jwe.enc#ECDH_ES
98+
* @see Jwe.enc#ECDH_ES_A128KW
99+
* @see Jwe.enc#ECDH_ES_A192KW
100+
* @see Jwe.enc#ECDH_ES_A256KW
101101
*/
102102
byte[] getAgreementPartyVInfo();
103103

@@ -113,9 +113,9 @@ public interface JweHeader extends ProtectedHeader {
113113
* automatically when producing the encryption key.</p>
114114
*
115115
* @return the 96-bit initialization vector generated during key encryption, or {@code null} if not present.
116-
* @see Jwts.KEY#A128GCMKW
117-
* @see Jwts.KEY#A192GCMKW
118-
* @see Jwts.KEY#A256GCMKW
116+
* @see Jwe.enc#A128GCMKW
117+
* @see Jwe.enc#A192GCMKW
118+
* @see Jwe.enc#A256GCMKW
119119
*/
120120
byte[] getInitializationVector();
121121

@@ -130,9 +130,9 @@ public interface JweHeader extends ProtectedHeader {
130130
* automatically when producing the encryption key.</p>
131131
*
132132
* @return the 128-bit authentication tag resulting from key encryption, or {@code null} if not present.
133-
* @see Jwts.KEY#A128GCMKW
134-
* @see Jwts.KEY#A192GCMKW
135-
* @see Jwts.KEY#A256GCMKW
133+
* @see Jwe.enc#A128GCMKW
134+
* @see Jwe.enc#A192GCMKW
135+
* @see Jwe.enc#A256GCMKW
136136
*/
137137
byte[] getAuthenticationTag();
138138

@@ -143,9 +143,9 @@ public interface JweHeader extends ProtectedHeader {
143143
* @return the number of PBKDF2 iterations necessary to derive the key used during JWE encryption, or {@code null}
144144
* if not present.
145145
* @see <a href="https://www.rfc-editor.org/rfc/rfc7518.html#section-4.8.1.2">JWE <code>p2c</code> (PBES2 Count) Header Parameter</a>
146-
* @see Jwts.KEY#PBES2_HS256_A128KW
147-
* @see Jwts.KEY#PBES2_HS384_A192KW
148-
* @see Jwts.KEY#PBES2_HS512_A256KW
146+
* @see Jwe.enc#PBES2_HS256_A128KW
147+
* @see Jwe.enc#PBES2_HS384_A192KW
148+
* @see Jwe.enc#PBES2_HS512_A256KW
149149
*/
150150
Integer getPbes2Count();
151151

@@ -162,9 +162,9 @@ public interface JweHeader extends ProtectedHeader {
162162
* @return the PBKDF2 {@code Salt Input} value necessary to derive the key used during JWE encryption, or
163163
* {@code null} if not present.
164164
* @see <a href="https://www.rfc-editor.org/rfc/rfc7518.html#section-4.8.1.1">JWE <code>p2s</code> (PBES2 Salt Input) Header Parameter</a>
165-
* @see Jwts.KEY#PBES2_HS256_A128KW
166-
* @see Jwts.KEY#PBES2_HS384_A192KW
167-
* @see Jwts.KEY#PBES2_HS512_A256KW
165+
* @see Jwe.enc#PBES2_HS256_A128KW
166+
* @see Jwe.enc#PBES2_HS384_A192KW
167+
* @see Jwe.enc#PBES2_HS512_A256KW
168168
*/
169169
byte[] getPbes2Salt();
170170
}

api/src/main/java/io/jsonwebtoken/JweHeaderMutator.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ public interface JweHeaderMutator<T extends JweHeaderMutator<T>> extends Protect
3232
* @param info information about the JWE producer to use with key agreement algorithms.
3333
* @return the header for method chaining.
3434
* @see <a href="https://www.rfc-editor.org/rfc/rfc7518.html#section-4.6.1.2">JWE <code>apu</code> (Agreement PartyUInfo) Header Parameter</a>
35-
* @see Jwts.KEY#ECDH_ES
36-
* @see Jwts.KEY#ECDH_ES_A128KW
37-
* @see Jwts.KEY#ECDH_ES_A192KW
38-
* @see Jwts.KEY#ECDH_ES_A256KW
35+
* @see Jwe.enc#ECDH_ES
36+
* @see Jwe.enc#ECDH_ES_A128KW
37+
* @see Jwe.enc#ECDH_ES_A192KW
38+
* @see Jwe.enc#ECDH_ES_A256KW
3939
*/
4040
T agreementPartyUInfo(byte[] info);
4141

@@ -50,10 +50,10 @@ public interface JweHeaderMutator<T extends JweHeaderMutator<T>> extends Protect
5050
* @param info information about the JWE producer to use with key agreement algorithms.
5151
* @return the header for method chaining.
5252
* @see <a href="https://www.rfc-editor.org/rfc/rfc7518.html#section-4.6.1.2">JWE <code>apu</code> (Agreement PartyUInfo) Header Parameter</a>
53-
* @see Jwts.KEY#ECDH_ES
54-
* @see Jwts.KEY#ECDH_ES_A128KW
55-
* @see Jwts.KEY#ECDH_ES_A192KW
56-
* @see Jwts.KEY#ECDH_ES_A256KW
53+
* @see Jwe.enc#ECDH_ES
54+
* @see Jwe.enc#ECDH_ES_A128KW
55+
* @see Jwe.enc#ECDH_ES_A192KW
56+
* @see Jwe.enc#ECDH_ES_A256KW
5757
*/
5858
T agreementPartyUInfo(String info);
5959

@@ -64,10 +64,10 @@ public interface JweHeaderMutator<T extends JweHeaderMutator<T>> extends Protect
6464
* @param info information about the JWE recipient to use with key agreement algorithms.
6565
* @return the header for method chaining.
6666
* @see <a href="https://www.rfc-editor.org/rfc/rfc7518.html#section-4.6.1.3">JWE <code>apv</code> (Agreement PartyVInfo) Header Parameter</a>
67-
* @see Jwts.KEY#ECDH_ES
68-
* @see Jwts.KEY#ECDH_ES_A128KW
69-
* @see Jwts.KEY#ECDH_ES_A192KW
70-
* @see Jwts.KEY#ECDH_ES_A256KW
67+
* @see Jwe.enc#ECDH_ES
68+
* @see Jwe.enc#ECDH_ES_A128KW
69+
* @see Jwe.enc#ECDH_ES_A192KW
70+
* @see Jwe.enc#ECDH_ES_A256KW
7171
*/
7272
T agreementPartyVInfo(byte[] info);
7373

@@ -82,10 +82,10 @@ public interface JweHeaderMutator<T extends JweHeaderMutator<T>> extends Protect
8282
* @param info information about the JWE recipient to use with key agreement algorithms.
8383
* @return the header for method chaining.
8484
* @see <a href="https://www.rfc-editor.org/rfc/rfc7518.html#section-4.6.1.3">JWE <code>apv</code> (Agreement PartyVInfo) Header Parameter</a>
85-
* @see Jwts.KEY#ECDH_ES
86-
* @see Jwts.KEY#ECDH_ES_A128KW
87-
* @see Jwts.KEY#ECDH_ES_A192KW
88-
* @see Jwts.KEY#ECDH_ES_A256KW
85+
* @see Jwe.enc#ECDH_ES
86+
* @see Jwe.enc#ECDH_ES_A128KW
87+
* @see Jwe.enc#ECDH_ES_A192KW
88+
* @see Jwe.enc#ECDH_ES_A256KW
8989
*/
9090
T agreementPartyVInfo(String info);
9191

@@ -107,9 +107,9 @@ public interface JweHeaderMutator<T extends JweHeaderMutator<T>> extends Protect
107107
* greater than or equal to 1000 (one thousand).
108108
* @return the header for method chaining
109109
* @see <a href="https://www.rfc-editor.org/rfc/rfc7518.html#section-4.8.1.2">JWE <code>p2c</code> (PBES2 Count) Header Parameter</a>
110-
* @see Jwts.KEY#PBES2_HS256_A128KW
111-
* @see Jwts.KEY#PBES2_HS384_A192KW
112-
* @see Jwts.KEY#PBES2_HS512_A256KW
110+
* @see Jwe.enc#PBES2_HS256_A128KW
111+
* @see Jwe.enc#PBES2_HS384_A192KW
112+
* @see Jwe.enc#PBES2_HS512_A256KW
113113
* @see <a href="https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html#pbkdf2">OWASP PBKDF2 Iteration Recommendations</a>
114114
*/
115115
T pbes2Count(int count);

api/src/main/java/io/jsonwebtoken/JwtBuilder.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -871,12 +871,12 @@ public interface JwtBuilder extends ClaimsMutator<JwtBuilder> {
871871
* <ul>
872872
* <li>If the provided {@code key} is a {@link Password Password} instance,
873873
* the {@code KeyAlgorithm} used will be one of the three JWA-standard password-based key algorithms
874-
* ({@link Jwts.KEY#PBES2_HS256_A128KW PBES2_HS256_A128KW},
875-
* {@link Jwts.KEY#PBES2_HS384_A192KW PBES2_HS384_A192KW}, or
876-
* {@link Jwts.KEY#PBES2_HS512_A256KW PBES2_HS512_A256KW}) as determined by the {@code enc} algorithm's
874+
* ({@link Jwe.enc#PBES2_HS256_A128KW PBES2_HS256_A128KW},
875+
* {@link Jwe.enc#PBES2_HS384_A192KW PBES2_HS384_A192KW}, or
876+
* {@link Jwe.enc#PBES2_HS512_A256KW PBES2_HS512_A256KW}) as determined by the {@code enc} algorithm's
877877
* {@link AeadAlgorithm#getKeyBitLength() key length} requirement.</li>
878878
* <li>If the {@code key} is otherwise a standard {@code SecretKey}, the {@code KeyAlgorithm} will be
879-
* {@link Jwts.KEY#DIRECT DIRECT}, indicating that {@code key} should be used directly with the
879+
* {@link Jwe.enc#DIRECT DIRECT}, indicating that {@code key} should be used directly with the
880880
* {@code enc} algorithm. In this case, the {@code key} argument <em>MUST</em> be of sufficient strength to
881881
* use with the specified {@code enc} algorithm, otherwise an exception will be thrown during encryption. If
882882
* desired, secure-random keys suitable for an {@link AeadAlgorithm} may be generated using the algorithm's
@@ -908,7 +908,7 @@ public interface JwtBuilder extends ClaimsMutator<JwtBuilder> {
908908
* </ol>
909909
*
910910
* <p>Most application developers will reference one of the JWA
911-
* {@link Jwts.KEY standard key algorithms} and {@link Jwe.alg standard encryption algorithms}
911+
* {@link Jwe.enc standard key algorithms} and {@link Jwe.alg standard encryption algorithms}
912912
* when invoking this method, but custom implementations are also supported.</p>
913913
*
914914
* @param <K> the type of key that must be used with the specified {@code keyAlg} instance.
@@ -918,7 +918,7 @@ public interface JwtBuilder extends ClaimsMutator<JwtBuilder> {
918918
* @param enc the {@link AeadAlgorithm} algorithm used to encrypt the JWE
919919
* @return the JWE builder for method chaining.
920920
* @see Jwe.alg
921-
* @see Jwts.KEY
921+
* @see Jwe.enc
922922
*/
923923
<K extends Key> JwtBuilder encryptWith(K key, KeyAlgorithm<? super K, ?> keyAlg, AeadAlgorithm enc);
924924

api/src/main/java/io/jsonwebtoken/JwtParserBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ public interface JwtParserBuilder extends Builder<JwtParser> {
614614
*
615615
* <p><b>Standard Algorithms and Overrides</b></p>
616616
*
617-
* <p>All JWA-standard key encryption algorithms in the {@link Jwts.KEY} registry are supported by default and
617+
* <p>All JWA-standard key encryption algorithms in the {@link Jwe.enc} registry are supported by default and
618618
* do not need to be added. The collection may be useful however for removing some algorithms (for example,
619619
* any algorithms not used by the application, or those not compatible with application security requirements),
620620
* or for adding custom implementations.</p>
@@ -635,7 +635,7 @@ public interface JwtParserBuilder extends Builder<JwtParser> {
635635
*
636636
* @return the {@link NestedCollection} to use to configure the key algorithms available when parsing.
637637
* @see JwtBuilder#encryptWith(Key, KeyAlgorithm, AeadAlgorithm)
638-
* @see Jwts.KEY
638+
* @see Jwe.enc
639639
* @see <a href="https://www.rfc-editor.org/rfc/rfc7516.html#section-4.1.1">JWE &quot;alg&quot; (Algorithm) Header Parameter</a>
640640
* @see <a href="https://www.rfc-editor.org/rfc/rfc7518.html#section-7.1.1">Key Algorithm Name (id) requirements</a>
641641
* @since 0.12.0

0 commit comments

Comments
 (0)