|
|
@ -14,7 +14,9 @@ import java.io.ByteArrayInputStream; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.security.SecureRandom; |
|
|
|
import java.security.MessageDigest; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Base64; |
|
|
|
|
|
|
|
public class SeaweedWrite { |
|
|
|
|
|
|
@ -123,13 +125,20 @@ public class SeaweedWrite { |
|
|
|
final byte[] bytes, |
|
|
|
final long bytesOffset, final long bytesLength, |
|
|
|
byte[] cipherKey) throws IOException { |
|
|
|
MessageDigest md = null; |
|
|
|
try { |
|
|
|
md = MessageDigest.getInstance("MD5"); |
|
|
|
} catch (java.security.NoSuchAlgorithmException e) { |
|
|
|
} |
|
|
|
|
|
|
|
InputStream inputStream = null; |
|
|
|
if (cipherKey == null || cipherKey.length == 0) { |
|
|
|
md.update(bytes, (int) bytesOffset, (int) bytesLength); |
|
|
|
inputStream = new ByteArrayInputStream(bytes, (int) bytesOffset, (int) bytesLength); |
|
|
|
} else { |
|
|
|
try { |
|
|
|
byte[] encryptedBytes = SeaweedCipher.encrypt(bytes, (int) bytesOffset, (int) bytesLength, cipherKey); |
|
|
|
md.update(encryptedBytes); |
|
|
|
inputStream = new ByteArrayInputStream(encryptedBytes, 0, encryptedBytes.length); |
|
|
|
} catch (Exception e) { |
|
|
|
throw new IOException("fail to encrypt data", e); |
|
|
@ -140,6 +149,7 @@ public class SeaweedWrite { |
|
|
|
if (auth != null && auth.length() != 0) { |
|
|
|
post.addHeader("Authorization", "BEARER " + auth); |
|
|
|
} |
|
|
|
post.addHeader("Content-MD5", Base64.getEncoder().encodeToString(md.digest())); |
|
|
|
|
|
|
|
post.setEntity(MultipartEntityBuilder.create() |
|
|
|
.setMode(HttpMultipartMode.BROWSER_COMPATIBLE) |
|
|
|