How to get the md5sum of a file on Amazon's S3

前端 未结 11 2152

If I have existing files on Amazon\'s S3, what\'s the easiest way to get their md5sum without having to download the files?

Thanks

11条回答
  •  借酒劲吻你
    2020-12-01 01:13

    Here is the code to get MD5 hash as per 2017

    import java.security.MessageDigest;
    import java.security.NoSuchAlgorithmException;
    import org.apache.commons.codec.binary.Base64;
    public class GenerateMD5 {
    public static void main(String args[]) throws Exception{
        String s = "  http://www.example.com PUT POST DELETE * 3000   * GET * 3000  ";
    
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(s.getBytes());
            byte[] digest = md.digest();
            StringBuffer sb = new StringBuffer();
            /*for (byte b : digest) {
                sb.append(String.format("%02x", b & 0xff));
            }*/
            System.out.println(sb.toString());
            StringBuffer sbi = new StringBuffer();
            byte [] bytes = Base64.encodeBase64(digest);
            String finalString = new String(bytes);
            System.out.println(finalString);
        }
    }
    

    The commented code is where most people get it wrong changing it to hex

提交回复
热议问题