Skip to content

Commit 755c274

Browse files
authored
Switch Base64 codec, upgrade dependencies, and bump version to 1.5.0 (#109)
Switch Base64 codec, upgrade dependencies, and bump version to 1.5.0
1 parent 703d69a commit 755c274

File tree

10 files changed

+55
-33
lines changed

10 files changed

+55
-33
lines changed

CHANGELOG.md

+13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# Changelog
22

3+
## 1.5.0 -- 2019-05-30
4+
5+
### Minor Changes
6+
* Add dependency on Apache Commons Codec 1.12.
7+
* Use org.apache.commons.codec.binary.Base64 instead of java.util.Base64 so
8+
that the SDK can be used on systems that do not have java.util.Base64 but
9+
support Java 8 language features.
10+
11+
### Maintenance
12+
* Upgrade AWS Java SDK version from 1.11.169 to 1.11.561.
13+
* Upgrade Mockito from 2.23.4 to 2.28.1.
14+
* Upgrade Apache Commons Lang from 3.4 to 3.9.
15+
316
## 1.4.1 -- 2019-05-10
417

518
### Patches

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ You can get the latest release from Maven:
4545
<dependency>
4646
<groupId>com.amazonaws</groupId>
4747
<artifactId>aws-encryption-sdk-java</artifactId>
48-
<version>1.4.1</version>
48+
<version>1.5.0</version>
4949
</dependency>
5050
```
5151

pom.xml

+10-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.amazonaws</groupId>
66
<artifactId>aws-encryption-sdk-java</artifactId>
7-
<version>1.4.1</version>
7+
<version>1.5.0</version>
88
<packaging>jar</packaging>
99

1010
<name>aws-encryption-sdk-java</name>
@@ -42,7 +42,7 @@
4242
<dependency>
4343
<groupId>com.amazonaws</groupId>
4444
<artifactId>aws-java-sdk</artifactId>
45-
<version>1.11.169</version>
45+
<version>1.11.561</version>
4646
<optional>true</optional>
4747
</dependency>
4848

@@ -55,7 +55,7 @@
5555
<dependency>
5656
<groupId>org.mockito</groupId>
5757
<artifactId>mockito-core</artifactId>
58-
<version>2.23.4</version>
58+
<version>2.28.1</version>
5959
<scope>test</scope>
6060
</dependency>
6161

@@ -90,7 +90,13 @@
9090
<dependency>
9191
<groupId>org.apache.commons</groupId>
9292
<artifactId>commons-lang3</artifactId>
93-
<version>3.4</version>
93+
<version>3.9</version>
94+
</dependency>
95+
96+
<dependency>
97+
<groupId>commons-codec</groupId>
98+
<artifactId>commons-codec</artifactId>
99+
<version>1.12</version>
94100
</dependency>
95101
</dependencies>
96102

src/main/java/com/amazonaws/encryptionsdk/AwsCrypto.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616
import java.io.InputStream;
1717
import java.io.OutputStream;
1818
import java.nio.charset.StandardCharsets;
19-
import java.util.Base64;
2019
import java.util.Collections;
2120
import java.util.Map;
2221

22+
import org.apache.commons.codec.binary.Base64;
23+
2324
import com.amazonaws.encryptionsdk.exception.AwsCryptoException;
2425
import com.amazonaws.encryptionsdk.exception.BadCiphertextException;
2526
import com.amazonaws.encryptionsdk.internal.DecryptionHandler;
@@ -307,7 +308,7 @@ public <K extends MasterKey<K>> CryptoResult<String, K> encryptString(
307308
plaintext.getBytes(StandardCharsets.UTF_8),
308309
encryptionContext
309310
);
310-
return new CryptoResult<>(Base64.getEncoder().encodeToString(ctBytes.getResult()),
311+
return new CryptoResult<>(Base64.encodeBase64String(ctBytes.getResult()),
311312
ctBytes.getMasterKeys(), ctBytes.getHeaders());
312313
}
313314

@@ -423,7 +424,7 @@ public <K extends MasterKey<K>> CryptoResult<String, K> decryptString(
423424
Utils.assertNonNull(provider, "provider");
424425
final byte[] ciphertextBytes;
425426
try {
426-
ciphertextBytes = Base64.getDecoder().decode(Utils.assertNonNull(ciphertext, "ciphertext"));
427+
ciphertextBytes = Base64.decodeBase64(Utils.assertNonNull(ciphertext, "ciphertext"));
427428
} catch (final IllegalArgumentException ex) {
428429
throw new BadCiphertextException("Invalid base 64", ex);
429430
}

src/main/java/com/amazonaws/encryptionsdk/internal/TrailingSignatureAlgorithm.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec;
1515
import org.bouncycastle.math.ec.ECPoint;
1616

17-
import java.util.Base64;
17+
import org.apache.commons.codec.binary.Base64;
1818

1919
import com.amazonaws.encryptionsdk.CryptoAlgorithm;
2020

@@ -70,7 +70,7 @@ public String getRawSignatureAlgorithm() {
7070

7171
@Override
7272
public PublicKey deserializePublicKey(String keyString) {
73-
final ECPoint q = ecSpec.getCurve().decodePoint(Base64.getDecoder().decode(keyString));
73+
final ECPoint q = ecSpec.getCurve().decodePoint(Base64.decodeBase64(keyString));
7474

7575
ECPublicKeyParameters keyParams = new ECPublicKeyParameters(
7676
q,
@@ -82,7 +82,7 @@ public PublicKey deserializePublicKey(String keyString) {
8282

8383
@Override
8484
public String serializePublicKey(PublicKey key) {
85-
return Base64.getEncoder().encodeToString(((ECPublicKey)key).getQ().getEncoded(true));
85+
return Base64.encodeBase64String(((ECPublicKey)key).getQ().getEncoded(true));
8686
}
8787

8888
@Override

src/test/java/com/amazonaws/encryptionsdk/AwsCryptoTest.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import java.io.InputStream;
3333
import java.io.OutputStream;
3434
import java.nio.charset.StandardCharsets;
35-
import java.util.Base64;
3635
import java.util.EnumSet;
3736
import java.util.HashMap;
3837
import java.util.Map;
@@ -42,6 +41,8 @@
4241
import org.junit.Before;
4342
import org.junit.Test;
4443

44+
import org.apache.commons.codec.binary.Base64;
45+
4546
import com.amazonaws.encryptionsdk.caching.CachingCryptoMaterialsManager;
4647
import com.amazonaws.encryptionsdk.caching.LocalCryptoMaterialsCache;
4748
import com.amazonaws.encryptionsdk.exception.AwsCryptoException;
@@ -449,7 +450,7 @@ public void encryptBytesDecryptString() {
449450
encryptionContext).getResult();
450451
final String decryptedText = encryptionClient_.decryptString(
451452
masterKeyProvider,
452-
Base64.getEncoder().encodeToString(cipherText)).getResult();
453+
Base64.encodeBase64String(cipherText)).getResult();
453454

454455
assertEquals(plaintext, decryptedText);
455456
}
@@ -469,7 +470,7 @@ public void encryptStringDecryptBytes() {
469470
encryptionContext).getResult();
470471
final byte[] decryptedText = encryptionClient_.decryptData(
471472
masterKeyProvider,
472-
Base64.getDecoder().decode(ciphertext)).getResult();
473+
Base64.decodeBase64(ciphertext)).getResult();
473474

474475
assertArrayEquals(plaintextString.getBytes(StandardCharsets.UTF_8), decryptedText);
475476
}

src/test/java/com/amazonaws/encryptionsdk/XCompatDecryptTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import java.security.PrivateKey;
2424
import java.security.spec.PKCS8EncodedKeySpec;
2525
import java.util.ArrayList;
26-
import java.util.Base64;
2726
import java.util.Collection;
2827
import java.util.Collections;
2928
import java.util.HashMap;
@@ -33,6 +32,7 @@
3332
import javax.crypto.spec.SecretKeySpec;
3433

3534
import org.apache.commons.lang3.StringUtils;
35+
import org.apache.commons.codec.binary.Base64;
3636

3737
import org.bouncycastle.util.io.pem.PemReader;
3838

@@ -120,7 +120,7 @@ public static Collection<Object[]> data() throws Exception{
120120
byte[] keyBytes;
121121
switch ((String)thisKey.get("encoding")) {
122122
case "base64":
123-
keyBytes = Base64.getDecoder().decode(keyRaw);
123+
keyBytes = Base64.decodeBase64(keyRaw);
124124
break;
125125
case "pem":
126126
PemReader pemReader = new PemReader(new StringReader(keyRaw));
@@ -223,4 +223,4 @@ public void testDecryptFromFile() throws Exception {
223223
);
224224
assertArrayEquals(plaintextBytes, (byte[])decryptResult.getResult());
225225
}
226-
}
226+
}

src/test/java/com/amazonaws/encryptionsdk/caching/CacheIdentifierTests.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import java.lang.reflect.Method;
1010
import java.util.ArrayList;
1111
import java.util.Arrays;
12-
import java.util.Base64;
1312
import java.util.Collections;
1413
import java.util.HashMap;
1514
import java.util.List;
@@ -18,6 +17,7 @@
1817

1918
import org.bouncycastle.util.encoders.Hex;
2019
import org.junit.Test;
20+
import org.apache.commons.codec.binary.Base64;
2121

2222
import com.amazonaws.encryptionsdk.CryptoAlgorithm;
2323
import com.amazonaws.encryptionsdk.CryptoMaterialsManager;
@@ -84,7 +84,7 @@ void assertDecryptId(String partitionName, CryptoAlgorithm algo, List<KeyBlob> b
8484

8585
byte[] id = getCacheIdentifier(getCMM(partitionName), request);
8686

87-
assertEquals(expect, Base64.getEncoder().encodeToString(id));
87+
assertEquals(expect, Base64.encodeBase64String(id));
8888
}
8989

9090
void assertEncryptId(String partitionName, CryptoAlgorithm algo, Map<String, String> context, String expect) throws Exception {
@@ -95,7 +95,7 @@ void assertEncryptId(String partitionName, CryptoAlgorithm algo, Map<String, Str
9595

9696
byte[] id = getCacheIdentifier(getCMM(partitionName), request);
9797

98-
assertEquals(expect, Base64.getEncoder().encodeToString(id));
98+
assertEquals(expect, Base64.encodeBase64String(id));
9999
}
100100

101101
@Test

src/test/java/com/amazonaws/encryptionsdk/internal/StaticMasterKey.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import java.security.spec.KeySpec;
1010
import java.security.spec.PKCS8EncodedKeySpec;
1111
import java.security.spec.X509EncodedKeySpec;
12-
import java.util.Base64;
1312
import java.util.Collection;
1413
import java.util.Map;
1514
import java.util.Objects;
@@ -21,6 +20,8 @@
2120
import javax.crypto.SecretKey;
2221
import javax.crypto.spec.SecretKeySpec;
2322

23+
import org.apache.commons.codec.binary.Base64;
24+
2425
import com.amazonaws.encryptionsdk.CryptoAlgorithm;
2526
import com.amazonaws.encryptionsdk.DataKey;
2627
import com.amazonaws.encryptionsdk.EncryptedDataKey;
@@ -180,7 +181,7 @@ public DataKey<StaticMasterKey> decryptDataKey(CryptoAlgorithm algorithm,
180181
/**
181182
* Statically configured private key.
182183
*/
183-
private static final byte[] privateKey_v1 = Base64.getDecoder().decode(
184+
private static final byte[] privateKey_v1 = Base64.decodeBase64(
184185
("MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAKLpwqjYtYExVilW/Hg0ogWv9xZ+"
185186
+ "THj4IzvISLlPtK8W6KXMcqukfuxdYmndPv8UD1DbdHFYSSistdqoBN32vVQOQnJZyYm45i2TDOV0"
186187
+ "M2DtHtR6aMMlBLGtdPeeaT88nQfI1ORjRDyR1byMwomvmKifZYga6FjLt/sgqfSE9BUnAgMBAAEC"
@@ -197,7 +198,7 @@ public DataKey<StaticMasterKey> decryptDataKey(CryptoAlgorithm algorithm,
197198
/**
198199
* Statically configured public key.
199200
*/
200-
private static final byte[] publicKey_v1 = Base64.getDecoder().decode(
201+
private static final byte[] publicKey_v1 = Base64.decodeBase64(
201202
("MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCi6cKo2LWBMVYpVvx4NKIFr/cWfkx4+CM7yEi5"
202203
+ "T7SvFuilzHKrpH7sXWJp3T7/FA9Q23RxWEkorLXaqATd9r1UDkJyWcmJuOYtkwzldDNg7R7UemjD"
203204
+ "JQSxrXT3nmk/PJ0HyNTkY0Q8kdW8jMKJr5ion2WIGuhYy7f7IKn0hPQVJwIDAQAB")

src/test/java/com/amazonaws/encryptionsdk/model/ByteFormatCheckValues.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
package com.amazonaws.encryptionsdk.model;
1515

16-
import java.util.Base64;
16+
import org.apache.commons.codec.binary.Base64;
1717

1818
public class ByteFormatCheckValues {
1919
private static final String base64MessageId_ = "NQ/NXvg4mMN5zm5JFZHUWw==";
@@ -29,38 +29,38 @@ public class ByteFormatCheckValues {
2929
private static final String base64FinalFrameHeaderHash_ = "/b2fVFOxvnaM5vXDMGyyFPNTWMjuU/c/48qeH3uTHj0=";
3030

3131
public static byte[] getMessageId() {
32-
return Base64.getDecoder().decode(base64MessageId_);
32+
return Base64.decodeBase64(base64MessageId_);
3333
}
3434

3535
public static byte[] getEncryptedKey() {
36-
return Base64.getDecoder().decode(base64EncryptedKey_);
36+
return Base64.decodeBase64(base64EncryptedKey_);
3737
}
3838

3939
public static byte[] getPlaintextKey() {
40-
return Base64.getDecoder().decode(base64PlaintextKey_);
40+
return Base64.decodeBase64(base64PlaintextKey_);
4141
}
4242

4343
public static byte[] getCiphertextHeaderHash() {
44-
return Base64.getDecoder().decode(base64CiphertextHeaderHash_);
44+
return Base64.decodeBase64(base64CiphertextHeaderHash_);
4545
}
4646

4747
public static byte[] getCipherBlockHeaderHash() {
48-
return Base64.getDecoder().decode(base64BlockHeaderHash_);
48+
return Base64.decodeBase64(base64BlockHeaderHash_);
4949
}
5050

5151
public static byte[] getCipherFrameHeaderHash() {
52-
return Base64.getDecoder().decode(base64FrameHeaderHash_);
52+
return Base64.decodeBase64(base64FrameHeaderHash_);
5353
}
5454

5555
public static byte[] getCipherFinalFrameHeaderHash() {
56-
return Base64.getDecoder().decode(base64FinalFrameHeaderHash_);
56+
return Base64.decodeBase64(base64FinalFrameHeaderHash_);
5757
}
5858

5959
public static byte[] getNonce() {
60-
return Base64.getDecoder().decode(base64Nonce_);
60+
return Base64.decodeBase64(base64Nonce_);
6161
}
6262

6363
public static byte[] getTag() {
64-
return Base64.getDecoder().decode(base64Tag_);
64+
return Base64.decodeBase64(base64Tag_);
6565
}
6666
}

0 commit comments

Comments
 (0)