/** * Computes the MD5 hash of the given data and returns it as a hex string. * * @param data * @return * MD5 hash. * @throws NoSuchAlgorithmException * @throws IOException */ public static byte[] computeMD5Hash(byte[] data) throws NoSuchAlgorithmException, IOException { return computeMD5Hash(new ByteArrayInputStream(data)); }
/** * Computes the MD5 hash of the given data and returns it as a hex string. * * @param data * @return * MD5 hash. * @throws NoSuchAlgorithmException * @throws IOException */ public static byte[] computeMD5Hash(byte[] data) throws NoSuchAlgorithmException, IOException { return computeMD5Hash(new ByteArrayInputStream(data)); }
private String generateObjectKeyFromPassphrase(String passphrase, String password) throws Exception { String combinedString = passphrase + password; return ServiceUtils.toHex( ServiceUtils.computeMD5Hash(combinedString.getBytes(Constants.DEFAULT_ENCODING))) + "/jets3t.credentials"; }
private String generateObjectKeyFromPassphrase(String passphrase, String password) throws Exception { String combinedString = passphrase + password; return ServiceUtils.toHex( ServiceUtils.computeMD5Hash(combinedString.getBytes(Constants.DEFAULT_ENCODING))) + "/jets3t.credentials"; }
private String generateBucketNameFromPassphrase(String passphrase) throws Exception { return "jets3t-" + ServiceUtils.toHex( ServiceUtils.computeMD5Hash(passphrase.getBytes(Constants.DEFAULT_ENCODING))); }
private String generateBucketNameFromPassphrase(String passphrase) throws Exception { return "jets3t-" + ServiceUtils.toHex( ServiceUtils.computeMD5Hash(passphrase.getBytes(Constants.DEFAULT_ENCODING))); }
/** * Calculates the MD5 hash value of the given data object, and compares it * against this object's hash (as stored in the Content-MD5 header for * uploads, or the ETag header for downloads). * * @param downloadedData * @return * true if the calculated MD5 hash value of the bytes matches this object's * hash value, false otherwise. * * @throws NoSuchAlgorithmException * @throws FileNotFoundException * @throws IOException */ public boolean verifyData(byte[] downloadedData) throws NoSuchAlgorithmException, FileNotFoundException, IOException { return getMd5HashAsBase64().equals( ServiceUtils.toBase64( ServiceUtils.computeMD5Hash(downloadedData))); }
/** * Calculates the MD5 hash value of the given data object, and compares it * against this object's hash (as stored in the Content-MD5 header for * uploads, or the ETag header for downloads). * * @param downloadedData * @return * true if the calculated MD5 hash value of the bytes matches this object's * hash value, false otherwise. * * @throws NoSuchAlgorithmException * @throws FileNotFoundException * @throws IOException */ public boolean verifyData(byte[] downloadedData) throws NoSuchAlgorithmException, FileNotFoundException, IOException { return getMd5HashAsBase64().equals( ServiceUtils.toBase64( ServiceUtils.computeMD5Hash(downloadedData))); }
ServiceUtils.computeMD5Hash( new FileInputStream(downloadedFile))));
/** * Calculates the MD5 hash value of the given data object, and compares it * against this object's hash (as stored in the Content-MD5 header for * uploads, or the ETag header for downloads). * * @param downloadedDataStream * the input stream of a downloaded object. * * @return * true if the calculated MD5 hash value of the input stream matches this * object's hash value, false otherwise. * * @throws NoSuchAlgorithmException * @throws FileNotFoundException * @throws IOException */ public boolean verifyData(InputStream downloadedDataStream) throws NoSuchAlgorithmException, FileNotFoundException, IOException { return getMd5HashAsBase64().equals( ServiceUtils.toBase64( ServiceUtils.computeMD5Hash(downloadedDataStream))); }
/** * Calculates the MD5 hash value of the given data object, and compares it * against this object's hash (as stored in the Content-MD5 header for * uploads, or the ETag header for downloads). * * @param downloadedDataStream * the input stream of a downloaded object. * * @return * true if the calculated MD5 hash value of the input stream matches this * object's hash value, false otherwise. * * @throws NoSuchAlgorithmException * @throws FileNotFoundException * @throws IOException */ public boolean verifyData(InputStream downloadedDataStream) throws NoSuchAlgorithmException, FileNotFoundException, IOException { return getMd5HashAsBase64().equals( ServiceUtils.toBase64( ServiceUtils.computeMD5Hash(downloadedDataStream))); }
/** * 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 the target * service, 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 StorageObject(String key, String dataString) throws NoSuchAlgorithmException, IOException { this(key); ByteArrayInputStream bais = new ByteArrayInputStream( dataString.getBytes(Constants.DEFAULT_ENCODING)); setDataInputStream(bais); setContentLength(bais.available()); setContentType("text/plain; charset=utf-8"); setMd5Hash(ServiceUtils.computeMD5Hash(dataString.getBytes(Constants.DEFAULT_ENCODING))); }
@Override public void setLifecycleConfigImpl(String bucketName, LifecycleConfig config) throws S3ServiceException { Map<String, String> requestParameters = new HashMap<String, String>(); requestParameters.put("lifecycle", ""); String xml; String xmlMd5Hash; try { xml = config.toXml(); xmlMd5Hash = ServiceUtils.toBase64( ServiceUtils.computeMD5Hash(xml.getBytes(Constants.DEFAULT_ENCODING))); } catch (Exception e) { throw new S3ServiceException("Unable to build LifecycleConfig XML document", e); } Map<String, Object> metadata = new HashMap<String, Object>(); metadata.put("Content-MD5", xmlMd5Hash); try { performRestPut(bucketName, null, metadata, requestParameters, new StringEntity(xml, "text/plain", Constants.DEFAULT_ENCODING), true); } catch (ServiceException se) { throw new S3ServiceException(se); } catch (UnsupportedEncodingException e) { throw new S3ServiceException("Unable to encode XML document", e); } }
/** * 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 the target * service, 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 StorageObject(String key, String dataString) throws NoSuchAlgorithmException, IOException { this(key); ByteArrayInputStream bais = new ByteArrayInputStream( dataString.getBytes(Constants.DEFAULT_ENCODING)); setDataInputStream(bais); setContentLength(bais.available()); setContentType("text/plain; charset=utf-8"); setMd5Hash(ServiceUtils.computeMD5Hash(dataString.getBytes(Constants.DEFAULT_ENCODING))); }
/** * Create an object representing a file. The object is initialised with the file's name * as its key, the file's content as its data, a content type based on the file's extension * (see {@link Mimetypes}), and a content length matching the file's size. * The file's MD5 hash value is also calculated and provided to the destination service, * so the service can verify that no data are corrupted in transit. * <p> * <b>NOTE:</b> The automatic calculation of a file's MD5 hash digest as performed by * this constructor could take some time for large files, or for many small ones. * * @param file * the file the object will represent. This file must exist and be readable. * * @throws IOException when an i/o error occurred reading the file * @throws NoSuchAlgorithmException when this JRE doesn't support the MD5 hash algorithm */ public StorageObject(File file) throws NoSuchAlgorithmException, IOException { this(file.getName()); setContentLength(file.length()); setContentType(Mimetypes.getInstance().getMimetype(file)); if (!file.exists()) { throw new FileNotFoundException("Cannot read from file: " + file.getAbsolutePath()); } setDataInputFile(file); setMd5Hash(ServiceUtils.computeMD5Hash(new FileInputStream(file))); }
@Override public void setLifecycleConfigImpl(String bucketName, LifecycleConfig config) throws S3ServiceException { Map<String, String> requestParameters = new HashMap<String, String>(); requestParameters.put("lifecycle", ""); String xml; String xmlMd5Hash; try { xml = config.toXml(); xmlMd5Hash = ServiceUtils.toBase64( ServiceUtils.computeMD5Hash(xml.getBytes(Constants.DEFAULT_ENCODING))); } catch (Exception e) { throw new S3ServiceException("Unable to build LifecycleConfig XML document", e); } Map<String, Object> metadata = new HashMap<String, Object>(); metadata.put("Content-MD5", xmlMd5Hash); try { performRestPut(bucketName, null, metadata, requestParameters, new StringEntity(xml, "text/plain", Constants.DEFAULT_ENCODING), true); } catch (ServiceException se) { throw new S3ServiceException(se); } catch (UnsupportedEncodingException e) { throw new S3ServiceException("Unable to encode XML document", e); } }
/** * Create an object representing a file. The object is initialised with the file's name * as its key, the file's content as its data, a content type based on the file's extension * (see {@link Mimetypes}), and a content length matching the file's size. * The file's MD5 hash value is also calculated and provided to the destination service, * so the service can verify that no data are corrupted in transit. * <p> * <b>NOTE:</b> The automatic calculation of a file's MD5 hash digest as performed by * this constructor could take some time for large files, or for many small ones. * * @param file * the file the object will represent. This file must exist and be readable. * * @throws IOException when an i/o error occurred reading the file * @throws NoSuchAlgorithmException when this JRE doesn't support the MD5 hash algorithm */ public StorageObject(File file) throws NoSuchAlgorithmException, IOException { this(file.getName()); setContentLength(file.length()); setContentType(Mimetypes.getInstance().getMimetype(file)); if (!file.exists()) { throw new FileNotFoundException("Cannot read from file: " + file.getAbsolutePath()); } setDataInputFile(file); setMd5Hash(ServiceUtils.computeMD5Hash(new FileInputStream(file))); }
@Override public void checkoutFile(String name) throws IOException { name = FilenameUtils.separatorsToUnix(name); String pth = "claims/" + name + "/" + EncyptUtils.encHashArchiveName(Main.DSEID, Main.chunkStoreEncryptionEnabled); // this.s3clientLock.readLock().lock(); try { byte[] b = Long.toString(System.currentTimeMillis()).getBytes(); ObjectMetadata om = new ObjectMetadata(); String mds = BaseEncoding.base64().encode(ServiceUtils.computeMD5Hash(b)); om.setContentMD5(mds); om.addUserMetadata("md5sum", mds); om.setContentLength(b.length); PutObjectRequest creq = new PutObjectRequest(this.name, pth, new ByteArrayInputStream(b), om); s3Service.putObject(creq); if (this.simpleMD) this.updateObject(pth, om); } catch (OSSException e1) { throw new IOException(e1); } catch (Exception e1) { // SDFSLogger.getLog().error("error uploading", e1); throw new IOException(e1); } }
/** * Create an object representing binary data. The object is initialized with the given * key, the bytes as its data content, a content type of * <code>application/octet-stream</code>, and a content length matching the * byte array's length. * The MD5 hash value of the byte data is also calculated and provided to the target * service, so the service can verify that no data are corrupted in transit. * * @param key * the key name for the object. * @param data * the byte data the object will contain, cannot be null. * * @throws IOException * @throws NoSuchAlgorithmException when this JRE doesn't support the MD5 hash algorithm */ public StorageObject(String key, byte[] data) throws NoSuchAlgorithmException, IOException { this(key); ByteArrayInputStream bais = new ByteArrayInputStream(data); setDataInputStream(bais); setContentLength(bais.available()); setContentType(Mimetypes.MIMETYPE_OCTET_STREAM); setMd5Hash(ServiceUtils.computeMD5Hash(data)); }
/** * Create an object representing binary data. The object is initialized with the given * key, the bytes as its data content, a content type of * <code>application/octet-stream</code>, and a content length matching the * byte array's length. * The MD5 hash value of the byte data is also calculated and provided to the target * service, so the service can verify that no data are corrupted in transit. * * @param key * the key name for the object. * @param data * the byte data the object will contain, cannot be null. * * @throws IOException * @throws NoSuchAlgorithmException when this JRE doesn't support the MD5 hash algorithm */ public StorageObject(String key, byte[] data) throws NoSuchAlgorithmException, IOException { this(key); ByteArrayInputStream bais = new ByteArrayInputStream(data); setDataInputStream(bais); setContentLength(bais.available()); setContentType(Mimetypes.MIMETYPE_OCTET_STREAM); setMd5Hash(ServiceUtils.computeMD5Hash(data)); }