Class DigestUtil
-
Method Summary
Modifier and TypeMethodDescriptionstatic Stringbase64Digest(byte[] binaryData) static Stringbase64Digest(InputStream inputStream) Calculates a base64 MD5 digest for the content of an inputStream.static Stringbase64Digest(String salt, InputStream inputStream) Calculates a base64 MD5 digest for the content of an inputStream.static byte[]checksum(InputStream is, software.amazon.awssdk.core.checksums.Algorithm algorithm) Calculate a checksum for the given inputstream and algorithm.static StringchecksumFor(InputStream is, software.amazon.awssdk.core.checksums.Algorithm algorithm) Calculate a checksum for the given inputstream and algorithm.static StringchecksumFor(Path path, software.amazon.awssdk.core.checksums.Algorithm algorithm) Calculate a checksum for the given path and algorithm.static StringchecksumMultipart(List<Path> paths, software.amazon.awssdk.core.checksums.Algorithm algorithm) Calculates the checksum for a list of paths.static StringhexDigest(byte[] bytes) static Stringstatic StringhexDigest(InputStream inputStream) Calculates a hex encoded MD5 digest for the content of an inputStream.static Stringstatic StringhexDigest(String salt, InputStream inputStream) Calculates a hex encoded MD5 digest for the content of an inputStream.static StringhexDigestMultipart(List<Path> paths) Calculates a hex encoded MD5 digest for the contents of a list of paths.
-
Method Details
-
checksumFor
public static String checksumFor(Path path, software.amazon.awssdk.core.checksums.Algorithm algorithm) Calculate a checksum for the given path and algorithm.- Parameters:
path- Path containing the bytes to generate the checksum foralgorithm- algorithm to use- Returns:
- the checksum
-
checksumFor
public static String checksumFor(InputStream is, software.amazon.awssdk.core.checksums.Algorithm algorithm) Calculate a checksum for the given inputstream and algorithm.- Parameters:
is- InputStream containing the bytes to generate the checksum foralgorithm- algorithm to use- Returns:
- the checksum
-
checksum
public static byte[] checksum(InputStream is, software.amazon.awssdk.core.checksums.Algorithm algorithm) Calculate a checksum for the given inputstream and algorithm.- Parameters:
is- InputStream containing the bytes to generate the checksum foralgorithm- algorithm to use- Returns:
- the checksum
-
hexDigestMultipart
Calculates a hex encoded MD5 digest for the contents of a list of paths. This is a special case that emulates how AWS calculates the MD5 Checksums of the parts of a Multipart upload. API Stackoverflow Quote from Stackoverflow: Say you uploaded a 14MB file to a bucket without server-side encryption, and your part size is 5MB. Calculate 3 MD5 checksums corresponding to each part, i.e. the checksum of the first 5MB, the second 5MB, and the last 4MB. Then take the checksum of their concatenation. MD5 checksums are often printed as hex representations of binary data, so make sure you take the MD5 of the decoded binary concatenation, not of the ASCII or UTF-8 encoded concatenation. When that's done, add a hyphen and the number of parts to get the ETag.- Parameters:
paths- the list of paths.- Returns:
- A special hex digest that is used for files uploaded in parts.
-
checksumMultipart
public static String checksumMultipart(List<Path> paths, software.amazon.awssdk.core.checksums.Algorithm algorithm) Calculates the checksum for a list of paths. For multipart uploads, AWS takes the checksum of all parts, concatenates them, and then takes the checksum again. Then, they add a hyphen and the number of parts used to calculate the checksum. API -
hexDigest
-
hexDigest
-
hexDigest
-
hexDigest
Calculates a hex encoded MD5 digest for the content of an inputStream.Mainly used for comparison of files. E.g. After Putting a File to the Server, the Amazon S3-Client expects a hex encoded MD5 digest as the ETag, as part of the response Header to verify the validity of the transferred file.
- Parameters:
inputStream- the InputStream.- Returns:
- String Hex MD5 digest.
-
hexDigest
Calculates a hex encoded MD5 digest for the content of an inputStream.Mainly used for comparison of files. E.g. After Putting a File to the Server, the Amazon S3-Client expects a hex encoded MD5 digest as the ETag, as part of the response Header to verify the validity of the transferred file. For encrypted uploads, the returned digest may not be the same as the local client digest value.
- Parameters:
salt- Optional salt to add to be digested, for simulating encryption dependent digest.inputStream- the InputStream.- Returns:
- String Hex MD5 digest.
-
base64Digest
Calculates a base64 MD5 digest for the content of an inputStream.Mainly used for comparison of files. E.g. After Putting a File to the Server, the Amazon S3-Client expects a base64 MD5 digest, ETag, as part of the response Header to verify the validity of the transferred file.
- Parameters:
inputStream- the InputStream.- Returns:
- String Base64 MD5 digest.
-
base64Digest
Calculates a base64 MD5 digest for the content of an inputStream.Mainly used for comparison of files. E.g. After Putting a File to the Server, the Amazon S3-Client expects a base64 MD5 digest, ETag, as part of the response Header to verify the validity of the transferred file. For encrypted uploads, the returned digest may not be the same as the local client digest value.
- Parameters:
salt- Optional salt to add to be digested, for simulating encryption dependent digest.inputStream- the InputStream.- Returns:
- String Base64 MD5 digest.
-
base64Digest
-