001 package com.nimbusds.jose;
002
003
004 import net.jcip.annotations.Immutable;
005
006 import 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 simple wrapper for returning the cipher text, initialisation
012 * vector (IV), encrypted key and integrity value from {@link JWEEncrypter}
013 * implementations.
014 *
015 * @author Vladimir Dzhuvinov
016 * @version $version$ (2012-10-23)
017 */
018 @Immutable
019 public final class JWECryptoParts {
020
021
022 /**
023 * The encrypted key (optional).
024 */
025 private final Base64URL encryptedKey;
026
027
028 /**
029 * The initialisation vector (optional).
030 */
031 private final Base64URL iv;
032
033
034 /**
035 * The cipher text.
036 */
037 private final Base64URL cipherText;
038
039
040 /**
041 * The integrity value (optional).
042 */
043 private final Base64URL integrityValue;
044
045
046 /**
047 * Creates a new cryptograhic JWE parts instance.
048 *
049 * @param encryptedKey The encrypted key, {@code null} if not
050 * required by the encryption algorithm.
051 * @param iv The initialisation vector (IV), {@code null} if
052 * not required by the encryption algorithm.
053 * @param cipherText The cipher text. Must not be {@code null}.
054 * @param integrityValue The integrity value, {@code null} if the JWE
055 * algorithm provides built-in integrity check.
056 */
057 public JWECryptoParts(final Base64URL encryptedKey,
058 final Base64URL iv,
059 final Base64URL cipherText,
060 final Base64URL integrityValue) {
061
062 this.encryptedKey = encryptedKey;
063
064 this.iv = iv;
065
066 if (cipherText == null)
067 throw new IllegalArgumentException("The cipher text must not be null");
068
069 this.cipherText = cipherText;
070
071 this.integrityValue = integrityValue;
072 }
073
074
075 /**
076 * Gets the encrypted key.
077 *
078 * @return The encrypted key, {@code null} if not required by
079 * the JWE algorithm.
080 */
081 public Base64URL getEncryptedKey() {
082
083 return encryptedKey;
084 }
085
086
087 /**
088 * Gets the initialisation vector (IV).
089 *
090 * @return The initialisation vector (IV), {@code null} if not required
091 * by the JWE algorithm.
092 */
093 public Base64URL getInitializationVector() {
094
095 return iv;
096 }
097
098
099 /**
100 * Gets the cipher text.
101 *
102 * @return The cipher text.
103 */
104 public Base64URL getCipherText() {
105
106 return cipherText;
107 }
108
109
110 /**
111 * Gets the integrity value.
112 *
113 * @return The integrity value, {@code null} if the encryption
114 * algorithm provides built-in integrity checking.
115 */
116 public Base64URL getIntegrityValue() {
117
118 return integrityValue;
119 }
120 }