116 showTitle(
"Test: alg = RSA1_5, enc = A128CBC+HS256");
119 String encodedHeader =
"eyJhbGciOiJSU0ExXzUiLCJlbmMiOiJBMTI4Q0JDK0hTMjU2In0";
120 String plainText =
"No matter where you go, there you are.";
121 byte[] cmk = Base64Util.unsignedToBytes(
new int[] { 4, 211, 31, 197, 84, 157, 252, 254, 11, 100, 157, 250, 63,
122 170, 106, 206, 107, 124, 212, 45, 111, 107, 9, 219, 200, 177, 0, 240, 143, 156, 44, 207 });
124 BigInteger modulus =
new BigInteger(1, Base64Util.unsignedToBytes(
new int[] { 177, 119, 33, 13, 164, 30, 108,
125 121, 207, 136, 107, 242, 12, 224, 19, 226, 198, 134, 17, 71, 173, 75, 42, 61, 48, 162, 206, 161, 97,
126 108, 185, 234, 226, 219, 118, 206, 118, 5, 169, 224, 60, 181, 90, 85, 51, 123, 6, 224, 4, 122, 29, 230,
127 151, 12, 244, 127, 121, 25, 4, 85, 220, 144, 215, 110, 130, 17, 68, 228, 129, 138, 7, 130, 231, 40, 212,
128 214, 17, 179, 28, 124, 151, 178, 207, 20, 14, 154, 222, 113, 176, 24, 198, 73, 211, 113, 9, 33, 178, 80,
129 13, 25, 21, 25, 153, 212, 206, 67, 154, 147, 70, 194, 192, 183, 160, 83, 98, 236, 175, 85, 23, 97, 75,
130 199, 177, 73, 145, 50, 253, 206, 32, 179, 254, 236, 190, 82, 73, 67, 129, 253, 252, 220, 108, 136, 138,
131 11, 192, 1, 36, 239, 228, 55, 81, 113, 17, 25, 140, 63, 239, 146, 3, 172, 96, 60, 227, 233, 64, 255,
132 224, 173, 225, 228, 229, 92, 112, 72, 99, 97, 26, 87, 187, 123, 46, 50, 90, 202, 117, 73, 10, 153, 47,
133 224, 178, 163, 77, 48, 46, 154, 33, 148, 34, 228, 33, 172, 216, 89, 46, 225, 127, 68, 146, 234, 30, 147,
134 54, 146, 5, 133, 45, 78, 254, 85, 55, 75, 213, 86, 194, 218, 215, 163, 189, 194, 54, 6, 83, 36, 18, 153,
135 53, 7, 48, 89, 35, 66, 144, 7, 65, 154, 13, 97, 75, 55, 230, 132, 3, 13, 239, 71 }));
137 BigInteger exponent =
new BigInteger(1, Base64Util.unsignedToBytes(
new int[] { 1, 0, 1 }));
139 BigInteger privateExponent =
new BigInteger(1, Base64Util.unsignedToBytes(
new int[] { 84, 80, 150, 58, 165, 235,
140 242, 123, 217, 55, 38, 154, 36, 181, 221, 156, 211, 215, 100, 164, 90, 88, 40, 228, 83, 148, 54, 122, 4,
141 16, 165, 48, 76, 194, 26, 107, 51, 53, 179, 165, 31, 18, 198, 173, 78, 61, 56, 97, 252, 158, 140, 80,
142 63, 25, 223, 156, 36, 203, 214, 252, 120, 67, 180, 167, 3, 82, 243, 25, 97, 214, 83, 133, 69, 16, 104,
143 54, 160, 200, 41, 83, 164, 187, 70, 153, 111, 234, 242, 158, 175, 28, 198, 48, 211, 45, 148, 58, 23, 62,
144 227, 74, 52, 117, 42, 90, 41, 249, 130, 154, 80, 119, 61, 26, 193, 40, 125, 10, 152, 174, 227, 225, 205,
145 32, 62, 66, 6, 163, 100, 99, 219, 19, 253, 25, 105, 80, 201, 29, 252, 157, 237, 69, 1, 80, 171, 167, 20,
146 196, 156, 109, 249, 88, 0, 3, 152, 38, 165, 72, 87, 6, 152, 71, 156, 214, 16, 71, 30, 82, 51, 103, 76,
147 218, 63, 9, 84, 163, 249, 91, 215, 44, 238, 85, 101, 240, 148, 1, 82, 224, 91, 135, 105, 127, 84, 171,
148 181, 152, 210, 183, 126, 24, 46, 196, 90, 173, 38, 245, 219, 186, 222, 27, 240, 212, 194, 15, 66, 135,
149 226, 178, 190, 52, 245, 74, 65, 224, 81, 100, 85, 25, 204, 165, 203, 187, 175, 84, 100, 82, 15, 11, 23,
150 202, 151, 107, 54, 41, 207, 3, 136, 229, 134, 131, 93, 139, 50, 182, 204, 93, 130, 89 }));
152 PublicKey publicKey =
new RSAPublicKeyImpl(modulus, exponent);
153 RSAPrivateKey rsaPrivateKey =
new RSAPrivateKey(modulus, privateExponent);
156 JweEncrypterImpl encrypter =
new JweEncrypterImpl(KeyEncryptionAlgorithm.RSA1_5,
157 BlockEncryptionAlgorithm.A128CBC_PLUS_HS256, publicKey);
158 String encodedJweEncryptedKey = encrypter.generateEncryptedKey(cmk);
160 byte[] initVector = Base64Util
161 .unsignedToBytes(
new int[] { 3, 22, 60, 12, 43, 67, 104, 105, 108, 108, 105, 99, 111, 116, 104, 101 });
162 String encodedInitVector = Base64Util.base64urlencode(initVector);
163 assertEquals(encodedInitVector,
"AxY8DCtDaGlsbGljb3RoZQ");
165 String additionalAuthenticatedData = encodedHeader +
"." + encodedJweEncryptedKey +
"." + encodedInitVector;
167 Pair<String, String> cipherTextAndIntegrityValue = encrypter.generateCipherTextAndIntegrityValue(cmk,
168 initVector, additionalAuthenticatedData.getBytes(Util.UTF8_STRING_ENCODING),
169 plainText.getBytes(Util.UTF8_STRING_ENCODING));
170 String encodedCipherText = cipherTextAndIntegrityValue.getFirst();
171 String encodedAuthenticationTag = cipherTextAndIntegrityValue.getSecond();
173 String encodedJwe = encodedHeader +
"." + encodedJweEncryptedKey +
"." + encodedInitVector +
"." 174 + encodedCipherText +
"." + encodedAuthenticationTag;
175 System.out.println(
"JWE: " + encodedJwe);
178 JweDecrypterImpl decrypter =
new JweDecrypterImpl(rsaPrivateKey);
179 decrypter.setKeyEncryptionAlgorithm(KeyEncryptionAlgorithm.RSA1_5);
180 decrypter.setBlockEncryptionAlgorithm(BlockEncryptionAlgorithm.A128CBC_PLUS_HS256);
181 byte[] encryptionKey = decrypter.decryptEncryptionKey(encodedJweEncryptedKey);
182 assertEquals(encryptionKey, cmk);
184 String decodedPlainText = decrypter.decryptCipherText(encodedCipherText, encryptionKey, initVector,
185 Base64Util.base64urldecode(encodedAuthenticationTag),
186 additionalAuthenticatedData.getBytes(Util.UTF8_STRING_ENCODING));
187 assertEquals(decodedPlainText, plainText);
void showTitle(String title)
Definition: BaseTest.java:761