/** * Converts a Base64-encoded string to the original byte data. * * @param b64Data * a Base64-encoded string to decode. * * @return * bytes decoded from a Base64 string. */ public static byte[] fromBase64(String b64Data) { byte[] decoded = Base64.decodeBase64(stringToBytes(b64Data)); return decoded; }
/** * Converts a Base64-encoded string to the original byte data. * * @param b64Data * a Base64-encoded string to decode. * * @return * bytes decoded from a Base64 string. */ public static byte[] fromBase64(String b64Data) { byte[] decoded = Base64.decodeBase64(stringToBytes(b64Data)); return decoded; }
/** * Return lowercase hex-encoded HMAC message digest of given data using the * given key, using a crypto hash like "SHA256". * * @param key * @param data * @return HMAC SHA256 hash value. */ public static byte[] hmacSHA256(String key, String data) { return hmac(stringToBytes(key), stringToBytes(data), "SHA256"); }
/** * Return lowercase hex-encoded HMAC message digest of given data using the * given key, using a crypto hash like "SHA256". * * @param key * @param data * @return HMAC SHA256 hash value. */ public static byte[] hmacSHA256(String key, String data) { return hmac(stringToBytes(key), stringToBytes(data), "SHA256"); }
/** * * @param data * @param cryptoHash * @return lowercase hex-encoded hash value. */ public static byte[] hash(String data, String cryptoHash) { return hash(stringToBytes(data), cryptoHash); }
/** * * @param data * @param cryptoHash * @return lowercase hex-encoded hash value. */ public static byte[] hash(String data, String cryptoHash) { return hash(stringToBytes(data), cryptoHash); }
stringToBytes(awsSecretKey), Constants.HMAC_SHA1_ALGORITHM); b64 = Base64.encodeBase64(mac.doFinal(stringToBytes(canonicalString))); return new String(b64, Constants.DEFAULT_ENCODING);
stringToBytes(awsSecretKey), Constants.HMAC_SHA1_ALGORITHM); b64 = Base64.encodeBase64(mac.doFinal(stringToBytes(canonicalString))); return new String(b64, Constants.DEFAULT_ENCODING);
/** * Build the signing key for a REST/HTTP request to a storage * service for the AWS Request Signature version 4. * * @param secretAccessKey * account holder's secret access key * @param timestampISO8601 * timestamp of request creation in ISO8601 format * @param region * region to which the request will be sent * {@link "http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region"} * @return signing key according to AWS Request Signature version 4 */ public static byte[] awsV4BuildSigningKey( String secretAccessKey, String timestampISO8601, String region) { String service = "s3"; String datestampISO8601 = timestampISO8601.substring(0, 8); byte[] kDate = ServiceUtils.hmacSHA256( "AWS4" + secretAccessKey, datestampISO8601); byte[] kRegion = ServiceUtils.hmacSHA256( kDate, ServiceUtils.stringToBytes(region)); byte[] kService = ServiceUtils.hmacSHA256( kRegion, ServiceUtils.stringToBytes(service)); byte[] kSigning = ServiceUtils.hmacSHA256( kService, ServiceUtils.stringToBytes("aws4_request")); return kSigning; }
/** * Build the signing key for a REST/HTTP request to a storage * service for the AWS Request Signature version 4. * * @param secretAccessKey * account holder's secret access key * @param timestampISO8601 * timestamp of request creation in ISO8601 format * @param region * region to which the request will be sent * {@link "http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region"} * @return signing key according to AWS Request Signature version 4 */ public static byte[] awsV4BuildSigningKey( String secretAccessKey, String timestampISO8601, String region) { String service = "s3"; String datestampISO8601 = timestampISO8601.substring(0, 8); byte[] kDate = ServiceUtils.hmacSHA256( "AWS4" + secretAccessKey, datestampISO8601); byte[] kRegion = ServiceUtils.hmacSHA256( kDate, ServiceUtils.stringToBytes(region)); byte[] kService = ServiceUtils.hmacSHA256( kRegion, ServiceUtils.stringToBytes(service)); byte[] kSigning = ServiceUtils.hmacSHA256( kService, ServiceUtils.stringToBytes("aws4_request")); return kSigning; }
/** * Create an object representing text data. The object is initialized with the given * key, the given string as its data content (encoded as UTF-8), a content type of * <code>text/plain; charset=utf-8</code>, and a content length matching the * string's length. * The given string's MD5 hash value is also calculated and provided to S3, so the service * can verify that no data are corrupted in transit. * <p> * <b>NOTE:</b> The automatic calculation of the MD5 hash digest as performed by * this constructor could take some time for large strings, or for many small ones. * * @param key * the key name for the object. * @param dataString * the text data the object will contain. Text data will be encoded as UTF-8. * This string cannot be null. * * @throws IOException * @throws NoSuchAlgorithmException when this JRE doesn't support the MD5 hash algorithm */ public S3Object(String key, String dataString) throws NoSuchAlgorithmException, IOException { super(key, dataString); setSHA256Hash( ServiceUtils.hashSHA256(ServiceUtils.stringToBytes(dataString))); }
/** * Create an object representing text data. The object is initialized with the given * key, the given string as its data content (encoded as UTF-8), a content type of * <code>text/plain; charset=utf-8</code>, and a content length matching the * string's length. * The given string's MD5 hash value is also calculated and provided to S3, so the service * can verify that no data are corrupted in transit. * <p> * <b>NOTE:</b> The automatic calculation of the MD5 hash digest as performed by * this constructor could take some time for large strings, or for many small ones. * * @param key * the key name for the object. * @param dataString * the text data the object will contain. Text data will be encoded as UTF-8. * This string cannot be null. * * @throws IOException * @throws NoSuchAlgorithmException when this JRE doesn't support the MD5 hash algorithm */ public S3Object(String key, String dataString) throws NoSuchAlgorithmException, IOException { super(key, dataString); setSHA256Hash( ServiceUtils.hashSHA256(ServiceUtils.stringToBytes(dataString))); }
ServiceUtils.hashSHA256(ServiceUtils.stringToBytes(dataString)));
ServiceUtils.hashSHA256(ServiceUtils.stringToBytes(dataString)));
secretKey, timestampISO8601, region); String signature = ServiceUtils.toHex(ServiceUtils.hmacSHA256( signingKey, ServiceUtils.stringToBytes(stringToSign)));
secretKey, timestampISO8601, region); String signature = ServiceUtils.toHex(ServiceUtils.hmacSHA256( signingKey, ServiceUtils.stringToBytes(stringToSign)));
signingKey, ServiceUtils.stringToBytes(stringToSign)));
signingKey, ServiceUtils.stringToBytes(stringToSign)));