1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.forgerock.json.jose.jwe;
18
19 import org.forgerock.json.jose.exceptions.JweException;
20 import org.forgerock.json.jose.jwe.handlers.encryption.AESKeyWrapEncryptionHandler;
21 import org.forgerock.json.jose.jwe.handlers.encryption.DirectEncryptionHandler;
22 import org.forgerock.json.jose.jwe.handlers.encryption.EncryptionHandler;
23 import org.forgerock.json.jose.jwe.handlers.encryption.RSAEncryptionHandler;
24
25
26
27
28
29
30
31
32
33 public class EncryptionManager {
34
35
36
37
38
39
40
41
42 public EncryptionHandler getEncryptionHandler(JweHeader header) {
43
44 switch (header.getAlgorithm().getAlgorithmType()) {
45 case RSA:
46 return getEncryptionHandler(header.getAlgorithm(), header.getEncryptionMethod());
47 case DIRECT:
48 return getEncryptionHandler(header.getAlgorithm(), header.getEncryptionMethod());
49 case AES_KEYWRAP:
50 return getEncryptionHandler(header.getAlgorithm(), header.getEncryptionMethod());
51 default: {
52 throw new JweException("No Encryption Handler for unknown encryption algorithm, "
53 + header.getAlgorithm() + ".");
54 }
55 }
56 }
57
58
59
60
61
62
63
64
65
66 private EncryptionHandler getEncryptionHandler(JweAlgorithm algorithm, EncryptionMethod encryptionMethod) {
67
68 switch (algorithm) {
69 case RSAES_PKCS1_V1_5:
70 case RSA_OAEP:
71 case RSA_OAEP_256:
72 return new RSAEncryptionHandler(encryptionMethod, algorithm);
73 case DIRECT:
74 return new DirectEncryptionHandler(encryptionMethod);
75 case A128KW:
76 case A192KW:
77 case A256KW:
78 return new AESKeyWrapEncryptionHandler(encryptionMethod);
79 default:
80 throw new JweException("No Encryption Handler for unknown encryption method, "
81 + encryptionMethod + ", with algorithm, " + algorithm + ".");
82 }
83 }
84 }