001/* 002 * nimbus-jose-jwt 003 * 004 * Copyright 2012-2016, Connect2id Ltd. 005 * 006 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use 007 * this file except in compliance with the License. You may obtain a copy of the 008 * License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software distributed 013 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 014 * CONDITIONS OF ANY KIND, either express or implied. See the License for the 015 * specific language governing permissions and limitations under the License. 016 */ 017 018package com.nimbusds.jose; 019 020 021import com.nimbusds.jose.util.Base64URL; 022import net.jcip.annotations.Immutable; 023 024import java.util.Objects; 025 026 027/** 028 * The cryptographic parts of a JSON Web Encryption (JWE) object. 029 * 030 * @author Vladimir Dzhuvinov 031 * @version 2024-04-20 032 */ 033@Immutable 034public final class JWECryptoParts { 035 036 037 /** 038 * The modified JWE header (optional). 039 */ 040 private final JWEHeader header; 041 042 043 /** 044 * The encrypted key (optional). 045 */ 046 private final Base64URL encryptedKey; 047 048 049 /** 050 * The initialisation vector (optional). 051 */ 052 private final Base64URL iv; 053 054 055 /** 056 * The cipher text. 057 */ 058 private final Base64URL cipherText; 059 060 061 /** 062 * The authentication tag (optional). 063 */ 064 private final Base64URL authenticationTag; 065 066 067 /** 068 * Creates a new cryptographic JWE parts instance. 069 * 070 * @param encryptedKey The encrypted key, {@code null} if not 071 * required by the encryption algorithm. 072 * @param iv The initialisation vector (IV), 073 * {@code null} if not required by the 074 * encryption algorithm. 075 * @param cipherText The cipher text. Must not be {@code null}. 076 * @param authenticationTag The authentication tag, {@code null} if the 077 * JWE algorithm provides built-in integrity 078 * check. 079 */ 080 public JWECryptoParts(final Base64URL encryptedKey, 081 final Base64URL iv, 082 final Base64URL cipherText, 083 final Base64URL authenticationTag) { 084 085 this(null, encryptedKey, iv, cipherText, authenticationTag); 086 } 087 088 089 /** 090 * Creates a new cryptographic JWE parts instance. 091 * 092 * @param header The modified JWE header, {@code null} if 093 * not. 094 * @param encryptedKey The encrypted key, {@code null} if not 095 * required by the encryption algorithm. 096 * @param iv The initialisation vector (IV), 097 * {@code null} if not required by the 098 * encryption algorithm. 099 * @param cipherText The cipher text. Must not be {@code null}. 100 * @param authenticationTag The authentication tag, {@code null} if the 101 * JWE algorithm provides built-in integrity 102 * check. 103 */ 104 public JWECryptoParts(final JWEHeader header, 105 final Base64URL encryptedKey, 106 final Base64URL iv, 107 final Base64URL cipherText, 108 final Base64URL authenticationTag) { 109 110 this.header = header; 111 this.encryptedKey = encryptedKey; 112 this.iv = iv; 113 this.cipherText = Objects.requireNonNull(cipherText); 114 this.authenticationTag = authenticationTag; 115 } 116 117 118 /** 119 * Gets the modified JWE header. 120 * 121 * @return The modified JWE header, {@code null} of not. 122 */ 123 public JWEHeader getHeader() { 124 125 return header; 126 } 127 128 129 /** 130 * Gets the encrypted key. 131 * 132 * @return The encrypted key, {@code null} if not required by 133 * the JWE algorithm or {@code recipients} are specified. 134 */ 135 public Base64URL getEncryptedKey() { 136 137 return encryptedKey; 138 } 139 140 141 /** 142 * Gets the initialisation vector (IV). 143 * 144 * @return The initialisation vector (IV), {@code null} if not required 145 * by the JWE algorithm. 146 */ 147 public Base64URL getInitializationVector() { 148 149 return iv; 150 } 151 152 153 /** 154 * Gets the cipher text. 155 * 156 * @return The cipher text. 157 */ 158 public Base64URL getCipherText() { 159 160 return cipherText; 161 } 162 163 164 /** 165 * Gets the authentication tag. 166 * 167 * @return The authentication tag, {@code null} if the encryption 168 * algorithm provides built-in integrity checking. 169 */ 170 public Base64URL getAuthenticationTag() { 171 172 return authenticationTag; 173 } 174}