Example usage for org.apache.commons.codec.digest DigestUtils md5

List of usage examples for org.apache.commons.codec.digest DigestUtils md5

Introduction

In this page you can find the example usage for org.apache.commons.codec.digest DigestUtils md5.

Prototype

public static byte[] md5(String data) 

Source Link

Usage

From source file:S3DataManager.java

public UploadToS3Output uploadSourceToS3(Run<?, ?> build, Launcher launcher, TaskListener listener)
        throws Exception {
    Validation.checkS3SourceUploaderConfig(projectName, workspace);

    String localfileName = this.projectName + "-" + "source.zip";
    String sourceFilePath = workspace.getRemote();
    String zipFilePath = sourceFilePath.substring(0, sourceFilePath.lastIndexOf(File.separator))
            + File.separator + localfileName;
    File zipFile = new File(zipFilePath);

    if (!zipFile.getParentFile().exists()) {
        boolean dirMade = zipFile.getParentFile().mkdirs();
        if (!dirMade) {
            throw new Exception("Unable to create directory: " + zipFile.getParentFile().getAbsolutePath());
        }/*from   ww w.ja v a 2 s  .c  o m*/
    }

    ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipFilePath));
    try {
        zipSource(sourceFilePath, out, sourceFilePath);
    } finally {
        out.close();
    }

    File sourceZipFile = new File(zipFilePath);
    PutObjectRequest putObjectRequest = new PutObjectRequest(s3InputBucket, s3InputKey, sourceZipFile);

    // Add MD5 checksum as S3 Object metadata
    String zipFileMD5;
    try (FileInputStream fis = new FileInputStream(zipFilePath)) {
        zipFileMD5 = new String(org.apache.commons.codec.binary.Base64.encodeBase64(DigestUtils.md5(fis)),
                "UTF-8");
    }
    ObjectMetadata objectMetadata = new ObjectMetadata();
    objectMetadata.setContentMD5(zipFileMD5);
    objectMetadata.setContentLength(sourceZipFile.length());
    putObjectRequest.setMetadata(objectMetadata);

    LoggingHelper.log(listener, "Uploading code to S3 at location " + putObjectRequest.getBucketName() + "/"
            + putObjectRequest.getKey() + ". MD5 checksum is " + zipFileMD5);
    PutObjectResult putObjectResult = s3Client.putObject(putObjectRequest);

    return new UploadToS3Output(putObjectRequest.getBucketName() + "/" + putObjectRequest.getKey(),
            putObjectResult.getVersionId());
}

From source file:com.proofpoint.event.collector.combiner.S3CombineObjectMetadataStore.java

private boolean writeMetadataFile(EventPartition eventPartition, CombinedGroup combinedGroup, String sizeName) {
    byte[] json = jsonCodec.toJson(combinedGroup).getBytes(Charsets.UTF_8);
    URI metadataFile = toMetadataLocation(eventPartition, sizeName);
    try {/*from   www .  j  a v  a2 s .  co  m*/
        ObjectMetadata metadata = new ObjectMetadata();
        metadata.setContentLength(json.length);
        metadata.setContentMD5(Base64.encodeBase64String(DigestUtils.md5(json)));
        metadata.setContentType(MediaType.APPLICATION_JSON);
        InputStream input = new ByteArrayInputStream(json);
        s3Service.putObject(getS3Bucket(metadataFile), getS3ObjectKey(metadataFile), input, metadata);
        return true;
    } catch (AmazonClientException e) {
        log.warn(e, "error writing metadata file: %s", metadataFile);
        return false;
    }
}

From source file:net.bryansaunders.jee6divelog.service.rest.RestApiTest.java

/**
 * Generates Headers for the Logged In User.
 * // ww  w  .j  a v a  2 s  .  c  om
 * @param requestMethod
 *            HTTP Request Method
 * @param requestUrl
 *            Request URL
 * @param privateApiKey
 *            Private API Key
 * @param publicApiKey
 *            Public API Key
 * @param jsonContent
 *            JSON Content String
 * @return Header Map
 */
protected Map<String, String> generateLoginHeaders(final String requestMethod, final String requestUrl,
        final String jsonContent, final String privateApiKey, final String publicApiKey) {
    final Map<String, String> headerMap = new HashMap<String, String>();

    final String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
    final String contentType = MediaType.APPLICATION_JSON;
    final String contentMd5 = "";
    if (jsonContent != null) {
        DigestUtils.md5(jsonContent);
    }

    final String signature = SecurityUtils.generateRestSignature(requestMethod, contentType, contentMd5, date,
            requestUrl, privateApiKey);

    headerMap.put(HttpHeaders.DATE, date);
    headerMap.put(HttpHeaders.CONTENT_TYPE, contentType);
    headerMap.put(RestApi.CONTENT_MD5_HEADER, contentMd5);
    headerMap.put(RestApi.PUBLIC_KEY_HEADER, publicApiKey);
    headerMap.put(RestApi.SIGNATURE_HEADER, signature);

    return headerMap;
}

From source file:com.dc.ssh.client.shell.AbstractSshClient.java

private void addIdentity(NodeCredentials credential) throws JSchException {
    if (credential.isKeySupport()) {
        String key = new String(DigestUtils.md5(credential.getPrivateKey()));
        if (!jsch.getIdentityNames().contains(key)) {
            jsch.addIdentity(key, credential.getPrivateKey(), null, null);
        }//  w  ww  .  ja v  a 2 s .  co  m
    }
}

From source file:jobhunter.persistence.Persistence.java

private void updateLastMod(final File file) {
    this.lastModification = file.lastModified();
    try (InputStream in = new FileInputStream(file)) {
        this.md5sum = DigestUtils.md5(in);
    } catch (IOException e) {
        l.error("Failed to read MD5 checksum from {}", file.toString(), e);
    }// w  ww . j a v a 2s .c o  m
    l.debug("File was last modified on {} with MD5 {}", lastModification, this.md5sum.toString());
}

From source file:com.swisscom.refimpl.boundary.MIB2Client.java

private void addSignature(HttpRequestBase request, String methodByName, String path, String merchantId,
        String contentType, byte[] data) {
    RequestSignInformations reqSign = new RequestSignInformations();
    reqSign.setDate(RFC_822_DATE_FORMAT_TZ_GMT.format(new Date()));
    reqSign.setMethod(methodByName);/* ww  w.j av a 2  s .  c  o  m*/
    reqSign.setPath(path);
    reqSign.setData(data);
    reqSign.setContentType(contentType);

    if (merchantId != null) {
        request.addHeader("x-merchant-id", merchantId);
    }

    String sig;
    try {
        sig = new Signer().buildSignature(reqSign, Constants.SEC_KEY);
        request.addHeader("x-scs-signature", sig);
        request.addHeader("x-scs-date", reqSign.getDate());
        if (data != null) {
            request.addHeader("content-md5", new String(Base64.encodeBase64(DigestUtils.md5(data))));
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.util.io.FileProtection.java

/**
 * Computes and returns the message digest for the specified file.
 * /*from w  ww. ja  v  a  2s  . com*/
 * @param file the file to be validated
 * @return the message digest for the specified file
 * @throws IOException if an I/O error occurred
 */
private static byte[] computeDigest(File file) throws IOException {
    InputStream is = null;

    try {
        is = new FileInputStream(file);

        return DigestUtils.md5(is);
    } finally {
        if (is != null) {
            is.close();
        }
    }
}

From source file:jobhunter.persistence.Persistence.java

@SuppressWarnings("unused")
private void updateLastMod(final File file, final InputStream in) throws IOException {
    this.lastModification = file.lastModified();
    this.md5sum = DigestUtils.md5(in);
}

From source file:com.netflix.spinnaker.front50.model.S3Support.java

public void update(String id, T item) {
    try {//from w w  w  .j  a  v a 2  s  . co  m
        byte[] bytes = objectMapper.writeValueAsBytes(item);

        ObjectMetadata objectMetadata = new ObjectMetadata();
        objectMetadata.setContentLength(bytes.length);
        objectMetadata.setContentMD5(
                new String(org.apache.commons.codec.binary.Base64.encodeBase64(DigestUtils.md5(bytes))));

        amazonS3.putObject(bucket, buildS3Key(id), new ByteArrayInputStream(bytes), objectMetadata);
        writeLastModified();
    } catch (JsonProcessingException e) {
        throw new IllegalStateException(e);
    }
}

From source file:main.java.utils.Utility.java

public static long md5Hash(String key) {
    byte[] value = DigestUtils.md5(key.getBytes());
    return Utility.convertByteToUnsignedLong(value);
}