Class DigestUtil

java.lang.Object
com.adobe.testing.s3mock.util.DigestUtil

public class DigestUtil extends Object
Util-Class for the creation of Digests. These are digests as expected in S3 responses by the AWS SDKs, so they may be generated using algorithms otherwise not expected to be used for this.
  • Constructor Details

    • DigestUtil

      public DigestUtil()
  • Method Details

    • hexDigestMultipart

      public static String hexDigestMultipart(List<Path> paths) throws IOException
      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: 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.
      Throws:
      IOException - if a path could not be accessed.
    • hexDigest

      public static String hexDigest(byte[] bytes)
    • hexDigest

      public static String hexDigest(File file)
    • hexDigest

      public static String hexDigest(String salt, File file)
    • hexDigest

      public static String hexDigest(InputStream inputStream)
      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

      public static String hexDigest(String salt, InputStream inputStream)
      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

      public static String base64Digest(InputStream inputStream)
      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

      public static String base64Digest(String salt, InputStream inputStream)
      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

      public static String base64Digest(byte[] binaryData)