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 net.jcip.annotations.Immutable; 022 023import com.nimbusds.jose.util.Base64URL; 024 025 026/** 027 * The cryptographic parts of a JSON Web Encryption (JWE) object. This class is 028 * an immutable wrapper for returning the cipher text, initialisation vector 029 * (IV), encrypted key and authentication authTag from {@link JWEEncrypter} 030 * implementations. 031 * 032 * @author Vladimir Dzhuvinov 033 * @version 2014-07-11 034 */ 035@Immutable 036public final class JWECryptoParts { 037 038 039 /** 040 * The modified JWE header (optional). 041 */ 042 private final JWEHeader header; 043 044 045 /** 046 * The encrypted key (optional). 047 */ 048 private final Base64URL encryptedKey; 049 050 051 /** 052 * The initialisation vector (optional). 053 */ 054 private final Base64URL iv; 055 056 057 /** 058 * The cipher text. 059 */ 060 private final Base64URL cipherText; 061 062 063 /** 064 * The authentication tag (optional). 065 */ 066 private final Base64URL authenticationTag; 067 068 069 /** 070 * Creates a new cryptographic JWE parts instance. 071 * 072 * @param encryptedKey The encrypted key, {@code null} if not 073 * required by the encryption algorithm. 074 * @param iv The initialisation vector (IV), 075 * {@code null} if not required by the 076 * encryption algorithm. 077 * @param cipherText The cipher text. Must not be {@code null}. 078 * @param authenticationTag The authentication tag, {@code null} if the 079 * JWE algorithm provides built-in integrity 080 * check. 081 */ 082 public JWECryptoParts(final Base64URL encryptedKey, 083 final Base64URL iv, 084 final Base64URL cipherText, 085 final Base64URL authenticationTag) { 086 087 this(null, encryptedKey, iv, cipherText, authenticationTag); 088 } 089 090 091 /** 092 * Creates a new cryptographic JWE parts instance. 093 * 094 * @param header The modified JWE header, {@code null} if 095 * not. 096 * @param encryptedKey The encrypted key, {@code null} if not 097 * required by the encryption algorithm. 098 * @param iv The initialisation vector (IV), 099 * {@code null} if not required by the 100 * encryption algorithm. 101 * @param cipherText The cipher text. Must not be {@code null}. 102 * @param authenticationTag The authentication tag, {@code null} if the 103 * JWE algorithm provides built-in integrity 104 * check. 105 */ 106 public JWECryptoParts(final JWEHeader header, 107 final Base64URL encryptedKey, 108 final Base64URL iv, 109 final Base64URL cipherText, 110 final Base64URL authenticationTag) { 111 112 this.header = header; 113 114 this.encryptedKey = encryptedKey; 115 116 this.iv = iv; 117 118 if (cipherText == null) { 119 120 throw new IllegalArgumentException("The cipher text must not be null"); 121 } 122 123 this.cipherText = cipherText; 124 125 this.authenticationTag = authenticationTag; 126 } 127 128 129 /** 130 * Gets the modified JWE header. 131 * 132 * @return The modified JWE header, {@code null} of not. 133 */ 134 public JWEHeader getHeader() { 135 136 return header; 137 } 138 139 140 /** 141 * Gets the encrypted key. 142 * 143 * @return The encrypted key, {@code null} if not required by 144 * the JWE algorithm. 145 */ 146 public Base64URL getEncryptedKey() { 147 148 return encryptedKey; 149 } 150 151 152 /** 153 * Gets the initialisation vector (IV). 154 * 155 * @return The initialisation vector (IV), {@code null} if not required 156 * by the JWE algorithm. 157 */ 158 public Base64URL getInitializationVector() { 159 160 return iv; 161 } 162 163 164 /** 165 * Gets the cipher text. 166 * 167 * @return The cipher text. 168 */ 169 public Base64URL getCipherText() { 170 171 return cipherText; 172 } 173 174 175 /** 176 * Gets the authentication tag. 177 * 178 * @return The authentication tag, {@code null} if the encryption 179 * algorithm provides built-in integrity checking. 180 */ 181 public Base64URL getAuthenticationTag() { 182 183 return authenticationTag; 184 } 185}