/** * Returns the MD5 in base64 for the given byte array. */ public static String md5AsBase64(byte[] input) { return BinaryUtils.toBase64(computeMD5Hash(input)); }
/** * Returns the MD5 in base64 for the given file. */ public static String md5AsBase64(File file) throws FileNotFoundException, IOException { return BinaryUtils.toBase64(computeMD5Hash(file)); } }
/** * Returns the MD5 in base64 for the data from the given input stream. * Note this method closes the given input stream upon completion. */ public static String md5AsBase64(InputStream is) throws IOException { return BinaryUtils.toBase64(computeMD5Hash(is)); }
/** * Returns the MD5 in base64 for the data from the given input stream. * Note this method closes the given input stream upon completion. */ public static String md5AsBase64(InputStream is) throws IOException { return BinaryUtils.toBase64(computeMD5Hash(is)); }
/** * Returns the MD5 in base64 for the given byte array. */ public static String md5AsBase64(byte[] input) { return BinaryUtils.toBase64(computeMD5Hash(input)); }
/** * Returns the MD5 in base64 for the given file. */ public static String md5AsBase64(File file) throws FileNotFoundException, IOException { return BinaryUtils.toBase64(computeMD5Hash(file)); } }
/** * Computes an RFC 2104-compliant HMAC signature for an array of bytes and * returns the result as a Base64 encoded string. */ private String signAndBase64Encode(byte[] data, String key, SigningAlgorithm algorithm) throws SdkClientException { try { byte[] signature = sign(data, key.getBytes(StandardCharsets.UTF_8), algorithm); return BinaryUtils.toBase64(signature); } catch (Exception e) { throw SdkClientException.builder() .message("Unable to calculate a request signature: " + e.getMessage()) .cause(e) .build(); } }
/** * Computes an RFC 2104-compliant HMAC signature for an array of bytes and * returns the result as a Base64 encoded string. */ private String signAndBase64Encode(byte[] data, String key, SigningAlgorithm algorithm) throws SdkClientException { try { byte[] signature = sign(data, key.getBytes(StandardCharsets.UTF_8), algorithm); return BinaryUtils.toBase64(signature); } catch (Exception e) { throw SdkClientException.builder() .message("Unable to calculate a request signature: " + e.getMessage()) .cause(e) .build(); } }
/** * Adds the specified value as Base64 encoded text to the current position of the in * progress XML document. * * @param b * The binary data to add to the XML document. * * @return This XMLWriter so that additional method calls can be chained * together. */ public XmlWriter value(ByteBuffer b) { append(escapeXmlEntities(BinaryUtils.toBase64(BinaryUtils.copyBytesFrom(b)))); return this; }
/** * Adds the specified value as Base64 encoded text to the current position of the in * progress XML document. * * @param b * The binary data to add to the XML document. * * @return This XMLWriter so that additional method calls can be chained * together. */ public XmlWriter value(ByteBuffer b) { append(escapeXmlEntities(BinaryUtils.toBase64(BinaryUtils.copyBytesFrom(b)))); return this; }
/** * Client side validation for {@link PutObjectRequest} * * @param response the response * @param executionAttributes the execution attributes */ public static void validatePutObjectChecksum(PutObjectResponse response, ExecutionAttributes executionAttributes) { SdkChecksum checksum = executionAttributes.getAttribute(CHECKSUM); if (response.eTag() != null) { String contentMd5 = BinaryUtils.toBase64(checksum.getChecksumBytes()); byte[] digest = BinaryUtils.fromBase64(contentMd5); byte[] ssHash = Base16Lower.decode(response.eTag().replace("\"", "")); if (!Arrays.equals(digest, ssHash)) { throw SdkClientException.create("Data read has a different checksum than expected."); } } }