1 /*
2 * The contents of this file are subject to the terms of the Common Development and
3 * Distribution License (the License). You may not use this file except in compliance with the
4 * License.
5 *
6 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
7 * specific language governing permission and limitations under the License.
8 *
9 * When distributing Covered Software, include this CDDL Header Notice in each file and include
10 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
11 * Header, with the fields enclosed by brackets [] replaced by your own identifying
12 * information: "Portions copyright [year] [name of copyright owner]".
13 *
14 * Copyright 2013-2016 ForgeRock AS.
15 */
16
17 package org.forgerock.json.jose.jwe;
18
19 import java.util.Arrays;
20
21 /**
22 * This class represents the result from the encryption process of the JWT plaintext.
23 *
24 * @since 2.0.0
25 */
26 public class JweEncryption {
27
28 private final byte[] ciphertext;
29 private final byte[] authenticationTag;
30
31 /**
32 * Constructs a new JweEncryption object with the given ciphertext and authentication tag.
33 *
34 * @param ciphertext The ciphertext.
35 * @param authenticationTag The authentication tag.
36 */
37 public JweEncryption(byte[] ciphertext, byte[] authenticationTag) {
38 this.ciphertext = ciphertext;
39 this.authenticationTag = authenticationTag;
40 }
41
42 /**
43 * Gets the ciphertext from the result of the encryption.
44 *
45 * @return The ciphertext.
46 */
47 public byte[] getCiphertext() {
48 return ciphertext;
49 }
50
51 /**
52 * Gets the authentication tag from the result of the encryption.
53 *
54 * @return The authentication tag.
55 */
56 public byte[] getAuthenticationTag() {
57 return authenticationTag;
58 }
59
60 @Override
61 public boolean equals(final Object o) {
62 if (this == o) {
63 return true;
64 }
65 if (o == null || getClass() != o.getClass()) {
66 return false;
67 }
68 final JweEncryption that = (JweEncryption) o;
69 return Arrays.equals(ciphertext, that.ciphertext) && Arrays.equals(authenticationTag, that.authenticationTag);
70 }
71
72 @Override
73 public int hashCode() {
74 return Arrays.deepHashCode(new Object[] { ciphertext, authenticationTag });
75 }
76 }