Skip to content

Commit

Permalink
Replaced Base64 from codec with java.util.Base64 (#35214)
Browse files Browse the repository at this point in the history
When building the track 2 SDK with maven, it flags the codec dependency as a "Forbidden dependency". But from JDK 8+, this can be replaced with java.util.Base64.
  • Loading branch information
NickKouds authored and skapur12 committed Apr 26, 2024
1 parent cab6ff6 commit 33649fd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
5 changes: 0 additions & 5 deletions sdk/batch/azure-compute-batch/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,5 @@
<version>4.13.2</version> <!-- {x-version-update;junit:junit;external_dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.15</version> <!-- {x-version-update;commons-codec:commons-codec;external_dependency} -->
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.azure.core.http.policy.HttpPipelinePolicy;
import com.azure.core.util.DateTimeRfc1123;
import com.azure.core.util.Header;
import org.apache.commons.codec.binary.Base64;
import java.util.Base64;
import reactor.core.publisher.Mono;

import javax.crypto.Mac;
Expand Down Expand Up @@ -49,7 +49,7 @@ private synchronized String sign(String stringToSign) {
// Encoding the Signature
// Signature=Base64(HMAC-SHA256(UTF8(StringToSign)))
byte[] digest = getHmac256().doFinal(stringToSign.getBytes("UTF-8"));
return Base64.encodeBase64String(digest);
return Base64.getEncoder().encodeToString(digest);
} catch (Exception e) {
throw new IllegalArgumentException("accessKey", e);
}
Expand All @@ -58,8 +58,9 @@ private synchronized String sign(String stringToSign) {
private synchronized Mac getHmac256() throws NoSuchAlgorithmException, InvalidKeyException {
if (this.hmacSha256 == null) {
// Initializes the HMAC-SHA256 Mac and SecretKey.
byte[] key = Base64.getDecoder().decode(batchSharedKeyCred.keyValue());
this.hmacSha256 = Mac.getInstance("HmacSHA256");
this.hmacSha256.init(new SecretKeySpec(Base64.decodeBase64(batchSharedKeyCred.keyValue()), "HmacSHA256"));
this.hmacSha256.init(new SecretKeySpec(key, "HmacSHA256"));
}
return this.hmacSha256;
}
Expand Down

0 comments on commit 33649fd

Please sign in to comment.