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