Skip to content
This repository has been archived by the owner on Nov 19, 2018. It is now read-only.

Commit

Permalink
Don't use internal sun.misc.BASE64Encoder
Browse files Browse the repository at this point in the history
The AWS SDK has its own base64 utility.
  • Loading branch information
almson authored and rnicholus committed Apr 6, 2016
1 parent f5ea923 commit 7a65295
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions java/s3/S3Uploads.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package fineuploader.s3;

import com.amazonaws.HttpMethod;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest;
import com.amazonaws.util.BinaryUtils;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import org.apache.commons.codec.binary.Hex;
import sun.misc.BASE64Encoder;

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
Expand All @@ -20,7 +18,6 @@
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.security.InvalidKeyException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
Expand Down Expand Up @@ -256,7 +253,7 @@ private String bytesToHex(byte[] bytes) {
private String base64EncodePolicy(JsonElement jsonElement) throws UnsupportedEncodingException
{
String policyJsonStr = jsonElement.toString();
String base64Encoded = (new BASE64Encoder()).encode(policyJsonStr.getBytes("UTF-8")).replaceAll("\n","").replaceAll("\r", "");
String base64Encoded = BinaryUtils.toBase64 (policyJsonStr.getBytes("UTF-8"));

return base64Encoded;
}
Expand All @@ -265,7 +262,7 @@ private String sign(String toSign) throws UnsupportedEncodingException, NoSuchAl
{
Mac hmac = Mac.getInstance("HmacSHA1");
hmac.init(new SecretKeySpec(AWS_SECRET_KEY.getBytes("UTF-8"), "HmacSHA1"));
String signature = (new BASE64Encoder()).encode(hmac.doFinal(toSign.getBytes("UTF-8"))).replaceAll("\n", "");
String signature = BinaryUtils.toBase64 (hmac.doFinal(toSign.getBytes("UTF-8")));

return signature;
}
Expand Down

0 comments on commit 7a65295

Please sign in to comment.