diff --git a/src/main/java/io/jsonwebtoken/Jwe.java b/src/main/java/io/jsonwebtoken/Jwe.java index 8c0e0b77..e90dbfcd 100644 --- a/src/main/java/io/jsonwebtoken/Jwe.java +++ b/src/main/java/io/jsonwebtoken/Jwe.java @@ -2,7 +2,7 @@ package io.jsonwebtoken; public interface Jwe extends Jwt { - byte[] getInitializationVector(); + byte[] getInitializationValue(); byte[] getAadTag(); } diff --git a/src/main/java/io/jsonwebtoken/impl/DefaultJweFactory.java b/src/main/java/io/jsonwebtoken/impl/DefaultJweFactory.java index 32cf5c03..382ac099 100644 --- a/src/main/java/io/jsonwebtoken/impl/DefaultJweFactory.java +++ b/src/main/java/io/jsonwebtoken/impl/DefaultJweFactory.java @@ -51,7 +51,7 @@ public class DefaultJweFactory { // so we use a 'null safe' variant: final byte[] encryptedKeyBytes = nullSafeBase64UrlDecode(base64UrlEncryptedKey, "Encrypted Key"); - final byte[] iv = base64UrlDecode(base64UrlIv, "Initialization Vector"); + final byte[] iv = base64UrlDecode(base64UrlIv, "Initialization Value"); final byte[] ciphertext = base64UrlDecode(base64UrlCiphertext, "Ciphertext"); diff --git a/src/main/java/io/jsonwebtoken/impl/DispatchingParser.java b/src/main/java/io/jsonwebtoken/impl/DispatchingParser.java index b54b45f2..d897dc9d 100644 --- a/src/main/java/io/jsonwebtoken/impl/DispatchingParser.java +++ b/src/main/java/io/jsonwebtoken/impl/DispatchingParser.java @@ -90,7 +90,7 @@ public class DispatchingParser { base64UrlEncodedTag = sb.toString(); Assert.notNull(base64UrlEncodedHeader, "Invalid compact JWE: base64Url JWE Protected Header is missing."); - Assert.notNull(base64UrlEncodedIv, "Invalid compact JWE: base64Url JWE Initialization Vector is missing."); + Assert.notNull(base64UrlEncodedIv, "Invalid compact JWE: base64Url JWE Initialization Value is missing."); Assert.notNull(base64UrlEncodedCiphertext, "Invalid compact JWE: base64Url JWE Ciphertext is missing."); Assert.notNull(base64UrlEncodedTag, "Invalid compact JWE: base64Url JWE Authentication Tag is missing."); @@ -113,7 +113,7 @@ public class DispatchingParser { DecryptionRequest dreq = DecryptionRequests.builder() .setKey(secretKey.getEncoded()) .setAdditionalAuthenticatedData(aad) - .setInitializationVector(iv) + .setInitializationValue(iv) .setCiphertext(ciphertext) .setAuthenticationTag(tag) .build(); diff --git a/src/main/java/io/jsonwebtoken/impl/crypto/AbstractAesEncryptionAlgorithm.java b/src/main/java/io/jsonwebtoken/impl/crypto/AbstractAesEncryptionAlgorithm.java index 70ea2018..f8dd37cc 100644 --- a/src/main/java/io/jsonwebtoken/impl/crypto/AbstractAesEncryptionAlgorithm.java +++ b/src/main/java/io/jsonwebtoken/impl/crypto/AbstractAesEncryptionAlgorithm.java @@ -21,7 +21,7 @@ public abstract class AbstractAesEncryptionAlgorithm implements EncryptionAlgori "generatedIvLength must be a positive number <= " + AES_BLOCK_SIZE; protected static final String DECRYPT_NO_IV = "This EncryptionAlgorithm implementation rejects decryption " + - "requests that do not include initialization vectors. AES ciphertext without an IV is weak and should " + + "requests that do not include initialization values. AES ciphertext without an IV is weak and should " + "never be used."; private final String name; @@ -93,7 +93,7 @@ public abstract class AbstractAesEncryptionAlgorithm implements EncryptionAlgori } } - protected byte[] generateInitializationVector(SecureRandom random) { + protected byte[] generateInitializationValue(SecureRandom random) { byte[] iv = new byte[this.generatedIvLength]; random.nextBytes(iv); return iv; @@ -124,18 +124,18 @@ public abstract class AbstractAesEncryptionAlgorithm implements EncryptionAlgori final SecureRandom random = getSecureRandom(req); - byte[] iv = req.getInitializationVector(); + byte[] iv = req.getInitializationValue(); int ivLength = length(iv); if (ivLength == 0) { - iv = generateInitializationVector(random); + iv = generateInitializationValue(random); } return iv; } protected byte[] assertDecryptionIv(DecryptionRequest req) throws IllegalArgumentException { - byte[] iv = req.getInitializationVector(); + byte[] iv = req.getInitializationValue(); Assert.notEmpty(iv, DECRYPT_NO_IV); return iv; } diff --git a/src/main/java/io/jsonwebtoken/impl/crypto/AbstractCryptoRequest.java b/src/main/java/io/jsonwebtoken/impl/crypto/AbstractCryptoRequest.java index 8effb4bb..afdc2a54 100644 --- a/src/main/java/io/jsonwebtoken/impl/crypto/AbstractCryptoRequest.java +++ b/src/main/java/io/jsonwebtoken/impl/crypto/AbstractCryptoRequest.java @@ -31,7 +31,7 @@ public abstract class AbstractCryptoRequest implements CryptoRequest { } @Override - public byte[] getInitializationVector() { + public byte[] getInitializationValue() { return this.iv; } } diff --git a/src/main/java/io/jsonwebtoken/impl/crypto/CryptoRequest.java b/src/main/java/io/jsonwebtoken/impl/crypto/CryptoRequest.java index a0756798..4aa44d42 100644 --- a/src/main/java/io/jsonwebtoken/impl/crypto/CryptoRequest.java +++ b/src/main/java/io/jsonwebtoken/impl/crypto/CryptoRequest.java @@ -28,17 +28,17 @@ public interface CryptoRequest { byte[] getKey(); /** - * Returns the initialization vector to use during encryption or decryption depending on the type of request. + * Returns the initialization value to use during encryption or decryption depending on the type of request. *

- *

If this value is {@code null} on an {@link EncryptionRequest}, a default initialization vector will be - * auto-generated, as it is never safe to use most cryptographic algorithms without initialization vectors + *

If this value is {@code null} on an {@link EncryptionRequest}, a default initialization value will be + * auto-generated, as it is never safe to use most cryptographic algorithms without initialization values * (such as AES).

*

- *

This implies that all decryption requests must always supply an initialization vector since encryption + *

This implies that all decryption requests must always supply an initialization value since encryption * will always have one.

* - * @return the initialization vector to use during encryption or decryption depending on the type of request. + * @return the initialization value to use during encryption or decryption depending on the type of request. */ - byte[] getInitializationVector(); + byte[] getInitializationValue(); } \ No newline at end of file diff --git a/src/main/java/io/jsonwebtoken/impl/crypto/DecryptionRequestBuilder.java b/src/main/java/io/jsonwebtoken/impl/crypto/DecryptionRequestBuilder.java index ae61aedb..a5f5ee4a 100644 --- a/src/main/java/io/jsonwebtoken/impl/crypto/DecryptionRequestBuilder.java +++ b/src/main/java/io/jsonwebtoken/impl/crypto/DecryptionRequestBuilder.java @@ -17,7 +17,7 @@ package io.jsonwebtoken.impl.crypto; public interface DecryptionRequestBuilder { - DecryptionRequestBuilder setInitializationVector(byte[] iv); + DecryptionRequestBuilder setInitializationValue(byte[] iv); DecryptionRequestBuilder setKey(byte[] key); diff --git a/src/main/java/io/jsonwebtoken/impl/crypto/DefaultDecryptionRequestBuilder.java b/src/main/java/io/jsonwebtoken/impl/crypto/DefaultDecryptionRequestBuilder.java index 98755975..2dee480c 100644 --- a/src/main/java/io/jsonwebtoken/impl/crypto/DefaultDecryptionRequestBuilder.java +++ b/src/main/java/io/jsonwebtoken/impl/crypto/DefaultDecryptionRequestBuilder.java @@ -32,7 +32,7 @@ public class DefaultDecryptionRequestBuilder implements DecryptionRequestBuilder private byte[] tag; @Override - public DecryptionRequestBuilder setInitializationVector(byte[] iv) { + public DecryptionRequestBuilder setInitializationValue(byte[] iv) { this.iv = clean(iv); return this; } diff --git a/src/main/java/io/jsonwebtoken/impl/crypto/DefaultEncryptionRequestBuilder.java b/src/main/java/io/jsonwebtoken/impl/crypto/DefaultEncryptionRequestBuilder.java index 55e99d3a..1b3441e4 100644 --- a/src/main/java/io/jsonwebtoken/impl/crypto/DefaultEncryptionRequestBuilder.java +++ b/src/main/java/io/jsonwebtoken/impl/crypto/DefaultEncryptionRequestBuilder.java @@ -36,7 +36,7 @@ public class DefaultEncryptionRequestBuilder implements EncryptionRequestBuilder } @Override - public EncryptionRequestBuilder setInitializationVector(byte[] iv) { + public EncryptionRequestBuilder setInitializationValue(byte[] iv) { this.iv = clean(iv); return this; } diff --git a/src/main/java/io/jsonwebtoken/impl/crypto/DefaultEncryptionResult.java b/src/main/java/io/jsonwebtoken/impl/crypto/DefaultEncryptionResult.java index a23028aa..df4f2cc9 100644 --- a/src/main/java/io/jsonwebtoken/impl/crypto/DefaultEncryptionResult.java +++ b/src/main/java/io/jsonwebtoken/impl/crypto/DefaultEncryptionResult.java @@ -31,7 +31,7 @@ public class DefaultEncryptionResult implements EncryptionResult { } @Override - public byte[] getInitializationVector() { + public byte[] getInitializationValue() { return this.iv; } diff --git a/src/main/java/io/jsonwebtoken/impl/crypto/EncryptionRequestBuilder.java b/src/main/java/io/jsonwebtoken/impl/crypto/EncryptionRequestBuilder.java index d83cf2f1..1e081e46 100644 --- a/src/main/java/io/jsonwebtoken/impl/crypto/EncryptionRequestBuilder.java +++ b/src/main/java/io/jsonwebtoken/impl/crypto/EncryptionRequestBuilder.java @@ -21,7 +21,7 @@ public interface EncryptionRequestBuilder { EncryptionRequestBuilder setSecureRandom(SecureRandom secureRandom); - EncryptionRequestBuilder setInitializationVector(byte[] iv); + EncryptionRequestBuilder setInitializationValue(byte[] iv); EncryptionRequestBuilder setKey(byte[] key); diff --git a/src/main/java/io/jsonwebtoken/impl/crypto/EncryptionResult.java b/src/main/java/io/jsonwebtoken/impl/crypto/EncryptionResult.java index 48950fcb..e6c9c093 100644 --- a/src/main/java/io/jsonwebtoken/impl/crypto/EncryptionResult.java +++ b/src/main/java/io/jsonwebtoken/impl/crypto/EncryptionResult.java @@ -17,7 +17,7 @@ package io.jsonwebtoken.impl.crypto; public interface EncryptionResult { - byte[] getInitializationVector(); + byte[] getInitializationValue(); byte[] getCiphertext(); diff --git a/src/main/java/io/jsonwebtoken/impl/crypto/InitializationVectorSource.java b/src/main/java/io/jsonwebtoken/impl/crypto/InitializationValueSource.java similarity index 88% rename from src/main/java/io/jsonwebtoken/impl/crypto/InitializationVectorSource.java rename to src/main/java/io/jsonwebtoken/impl/crypto/InitializationValueSource.java index 1baa33b3..8b661bb6 100644 --- a/src/main/java/io/jsonwebtoken/impl/crypto/InitializationVectorSource.java +++ b/src/main/java/io/jsonwebtoken/impl/crypto/InitializationValueSource.java @@ -15,7 +15,7 @@ */ package io.jsonwebtoken.impl.crypto; -public interface InitializationVectorSource { +public interface InitializationValueSource { - byte[] getInitializationVector(); + byte[] getInitializationValue(); } diff --git a/src/test/groovy/io/jsonwebtoken/impl/crypto/AbstractAesEncryptionAlgorithmTest.groovy b/src/test/groovy/io/jsonwebtoken/impl/crypto/AbstractAesEncryptionAlgorithmTest.groovy index fbb3c8dc..e9493655 100644 --- a/src/test/groovy/io/jsonwebtoken/impl/crypto/AbstractAesEncryptionAlgorithmTest.groovy +++ b/src/test/groovy/io/jsonwebtoken/impl/crypto/AbstractAesEncryptionAlgorithmTest.groovy @@ -50,7 +50,7 @@ class AbstractAesEncryptionAlgorithmTest { def req = EncryptionRequests.builder() .setAdditionalAuthenticatedData('foo'.getBytes()) - .setInitializationVector('iv'.getBytes()) + .setInitializationValue('iv'.getBytes()) .setKey(alg.generateKey().getEncoded()) .setPlaintext('bar'.getBytes()) .build(); @@ -89,7 +89,7 @@ class AbstractAesEncryptionAlgorithmTest { def req = EncryptionRequests.builder() .setAdditionalAuthenticatedData('foo'.getBytes()) - .setInitializationVector('iv'.getBytes()) + .setInitializationValue('iv'.getBytes()) .setKey(alg.generateKey().getEncoded()) .setPlaintext('bar'.getBytes()) .setSecureRandom(secureRandom) diff --git a/src/test/groovy/io/jsonwebtoken/impl/crypto/Aes128CbcHmacSha256Test.groovy b/src/test/groovy/io/jsonwebtoken/impl/crypto/Aes128CbcHmacSha256Test.groovy index e18d990d..c0110827 100644 --- a/src/test/groovy/io/jsonwebtoken/impl/crypto/Aes128CbcHmacSha256Test.groovy +++ b/src/test/groovy/io/jsonwebtoken/impl/crypto/Aes128CbcHmacSha256Test.groovy @@ -66,7 +66,7 @@ class Aes128CbcHmacSha256Test { EncryptionRequest request = EncryptionRequests.builder() .setAdditionalAuthenticatedData(A) - .setInitializationVector(IV) + .setInitializationValue(IV) .setKey(K) .setPlaintext(P) .build(); @@ -78,7 +78,7 @@ class Aes128CbcHmacSha256Test { byte[] resultCiphertext = result.getCiphertext() byte[] resultTag = result.getAuthenticationTag(); - byte[] resultIv = result.getInitializationVector(); + byte[] resultIv = result.getInitializationValue(); assertArrayEquals E, resultCiphertext assertArrayEquals T, resultTag @@ -89,7 +89,7 @@ class Aes128CbcHmacSha256Test { def dreq = DecryptionRequests.builder() .setAdditionalAuthenticatedData(A) .setCiphertext(resultCiphertext) - .setInitializationVector(resultIv) + .setInitializationValue(resultIv) .setKey(K) .setAuthenticationTag(resultTag) .build(); diff --git a/src/test/groovy/io/jsonwebtoken/impl/crypto/DefaultDecryptionRequestBuilderTest.groovy b/src/test/groovy/io/jsonwebtoken/impl/crypto/DefaultDecryptionRequestBuilderTest.groovy index 85537c77..f45411a7 100644 --- a/src/test/groovy/io/jsonwebtoken/impl/crypto/DefaultDecryptionRequestBuilderTest.groovy +++ b/src/test/groovy/io/jsonwebtoken/impl/crypto/DefaultDecryptionRequestBuilderTest.groovy @@ -35,11 +35,11 @@ class DefaultDecryptionRequestBuilderTest { def ciphertext = generateData() def req = new DefaultDecryptionRequestBuilder() - .setKey(key).setInitializationVector(iv).setCiphertext(ciphertext).build() + .setKey(key).setInitializationValue(iv).setCiphertext(ciphertext).build() assertTrue req instanceof DefaultDecryptionRequest assertSame key, req.getKey() - assertSame iv, req.getInitializationVector() + assertSame iv, req.getInitializationValue() assertSame ciphertext, req.getCiphertext() } @@ -55,8 +55,8 @@ class DefaultDecryptionRequestBuilderTest { } @Test - void testSetInitializationVectorWithEmptyArray() { - def b = new DefaultDecryptionRequestBuilder().setInitializationVector(new byte[0]) + void testSetInitializationValueWithEmptyArray() { + def b = new DefaultDecryptionRequestBuilder().setInitializationValue(new byte[0]) assertNull b.iv } diff --git a/src/test/groovy/io/jsonwebtoken/impl/crypto/DefaultEncryptionRequestBuilderTest.groovy b/src/test/groovy/io/jsonwebtoken/impl/crypto/DefaultEncryptionRequestBuilderTest.groovy index 8e7b893a..a64bc64e 100644 --- a/src/test/groovy/io/jsonwebtoken/impl/crypto/DefaultEncryptionRequestBuilderTest.groovy +++ b/src/test/groovy/io/jsonwebtoken/impl/crypto/DefaultEncryptionRequestBuilderTest.groovy @@ -21,12 +21,12 @@ class DefaultEncryptionRequestBuilderTest { def aad = generateData() def req = new DefaultEncryptionRequestBuilder() - .setKey(key).setInitializationVector(iv).setPlaintext(plaintext).setAdditionalAuthenticatedData(aad) + .setKey(key).setInitializationValue(iv).setPlaintext(plaintext).setAdditionalAuthenticatedData(aad) .build() assertTrue req instanceof DefaultAuthenticatedEncryptionRequest assertSame key, req.getKey() - assertSame iv, req.getInitializationVector() + assertSame iv, req.getInitializationValue() assertSame plaintext, req.getPlaintext() assertSame aad, req.getAssociatedData() } @@ -39,17 +39,17 @@ class DefaultEncryptionRequestBuilderTest { def plaintext = generateData() def req = new DefaultEncryptionRequestBuilder() - .setKey(key).setInitializationVector(iv).setPlaintext(plaintext).build() + .setKey(key).setInitializationValue(iv).setPlaintext(plaintext).build() assertTrue req instanceof DefaultEncryptionRequest assertSame key, req.getKey() - assertSame iv, req.getInitializationVector() + assertSame iv, req.getInitializationValue() assertSame plaintext, req.getPlaintext() } @Test - void testSetInitializationVectorWithEmptyArray() { - def b = new DefaultEncryptionRequestBuilder().setInitializationVector(new byte[0]) + void testSetInitializationValueWithEmptyArray() { + def b = new DefaultEncryptionRequestBuilder().setInitializationValue(new byte[0]) assertNull b.iv } diff --git a/src/test/groovy/io/jsonwebtoken/impl/crypto/EncryptionAlgorithmsTest.groovy b/src/test/groovy/io/jsonwebtoken/impl/crypto/EncryptionAlgorithmsTest.groovy index d0571c0c..7f213c75 100644 --- a/src/test/groovy/io/jsonwebtoken/impl/crypto/EncryptionAlgorithmsTest.groovy +++ b/src/test/groovy/io/jsonwebtoken/impl/crypto/EncryptionAlgorithmsTest.groovy @@ -53,7 +53,7 @@ class EncryptionAlgorithmsTest { def dreq = DecryptionRequests.builder() .setKey(key) - .setInitializationVector(result.getInitializationVector()) + .setInitializationValue(result.getInitializationValue()) .setAuthenticationTag(result.getAuthenticationTag()) .setCiphertext(result.getCiphertext()) .build() @@ -92,7 +92,7 @@ class EncryptionAlgorithmsTest { def dreq = DecryptionRequests.builder() .setAdditionalAuthenticatedData(AAD_BYTES) .setKey(key) - .setInitializationVector(result.getInitializationVector()) + .setInitializationValue(result.getInitializationValue()) .setAuthenticationTag(result.getAuthenticationTag()) .setCiphertext(result.getCiphertext()) .build() diff --git a/src/test/groovy/io/jsonwebtoken/impl/crypto/GcmAesEncryptionServiceTest.groovy b/src/test/groovy/io/jsonwebtoken/impl/crypto/GcmAesEncryptionServiceTest.groovy index 8f52401e..4dc5d9fb 100644 --- a/src/test/groovy/io/jsonwebtoken/impl/crypto/GcmAesEncryptionServiceTest.groovy +++ b/src/test/groovy/io/jsonwebtoken/impl/crypto/GcmAesEncryptionServiceTest.groovy @@ -40,7 +40,7 @@ class GcmAesEncryptionServiceTest { EncryptionRequest request = EncryptionRequests.builder() .setAdditionalAuthenticatedData(AAD) - .setInitializationVector(IV) + .setInitializationValue(IV) .setKey(K) .setPlaintext(P) .build(); @@ -52,7 +52,7 @@ class GcmAesEncryptionServiceTest { byte[] resultCiphertext = result.getCiphertext() byte[] resultTag = result.getAuthenticationTag(); - byte[] resultIv = result.getInitializationVector(); + byte[] resultIv = result.getInitializationValue(); assertArrayEquals E, resultCiphertext assertArrayEquals T, resultTag @@ -63,7 +63,7 @@ class GcmAesEncryptionServiceTest { AuthenticatedDecryptionRequest decryptionRequest = DecryptionRequests.builder() .setAdditionalAuthenticatedData(AAD) .setCiphertext(resultCiphertext) - .setInitializationVector(resultIv) + .setInitializationValue(resultIv) .setKey(K) .setAuthenticationTag(resultTag) .build(); diff --git a/src/test/groovy/io/jsonwebtoken/impl/crypto/HmacAesEncryptionAlgorithmTest.groovy b/src/test/groovy/io/jsonwebtoken/impl/crypto/HmacAesEncryptionAlgorithmTest.groovy index 651827e9..c44984c5 100644 --- a/src/test/groovy/io/jsonwebtoken/impl/crypto/HmacAesEncryptionAlgorithmTest.groovy +++ b/src/test/groovy/io/jsonwebtoken/impl/crypto/HmacAesEncryptionAlgorithmTest.groovy @@ -53,7 +53,7 @@ class HmacAesEncryptionAlgorithmTest { def dreq = DecryptionRequests.builder() .setKey(key) - .setInitializationVector(result.getInitializationVector()) + .setInitializationValue(result.getInitializationValue()) .setAuthenticationTag(result.getAuthenticationTag()) .setCiphertext(result.getCiphertext()) .build() @@ -108,7 +108,7 @@ class HmacAesEncryptionAlgorithmTest { def dreq = DecryptionRequests.builder() .setKey(key) - .setInitializationVector(result.getInitializationVector()) + .setInitializationValue(result.getInitializationValue()) .setAuthenticationTag(fakeTag) .setCiphertext(result.getCiphertext()) .build()