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

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

Introduction

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

Prototype

public static String md5Hex(String data) 

Source Link

Usage

From source file:com.proquest.demo.allinone.AllInOneCallable.java

/**
 * Process a single PDF, a single item from the list passed to the method above
 *
 * @return//from  ww  w .j av  a2s  .c o m
 * @throws Exception
 */
@Override
public List<GenericDataReturn> call() throws Exception {
    if (base == null) {
        base = new PDFLBase();
    }
    final PropertyReaderLib propertyReaderLib = new PropertyReaderLib(PropertyFileNames.MESSAGES);

    // Get local path for read and write files
    if (fileUtils == null) {
        fileUtils = new FileUtils();
    }

    try {
        // Init the JNI Lib
        base.initLibrary();

        boolean enableLicensedBehavior = false;
        final List<ActionCall> actions = data.getActionlist();
        for (ActionCall action : actions) {
            if (action.getPdfAction().equals(OperationOrder.REMOVE_PROTECTION.getOperationOrder())) {
                enableLicensedBehavior = true;
                break;
            }
        }
        if (enableLicensedBehavior) {
            base.enableLicensedBehavior();
        }

        if (doc == null) {
            doc = new Document(data.getInputFileS3());
        }

        // To save the file from local file system - Step 3
        doc = process(doc, data, base, propertyReaderLib);

    } catch (Exception e) {
        throw new Exception(e.getMessage());
    } finally {
        if (doc != null) {
            doc.close();
            doc = null;
        }
        // Dealloc the JNI Lib
        base.terminateLibrary();
    }

    if (data.getOutputFileLocal() != null && data.getOutputFileLocal().length() > 0) {

        // Upload the pdf file to S3 - Step 4
        final Path tempPath = Paths.get(data.getOutputFileLocal());
        final byte[] localPdfAsBytes = fileUtils.readFileFromTempLocation(tempPath);
        final String theDigest = DigestUtils.md5Hex(localPdfAsBytes);

        // Set new values from new file.
        data.setMd5(theDigest);
        data.setFileSize(Integer.toString(localPdfAsBytes.length));

        final Path outputPath = Paths.get(data.getOutputFileS3());
        final HttpCode codeReturned = fileUtils.writeFileToTempLocation(outputPath, localPdfAsBytes);

        final GenericDataReturn dataReturn = new GenericDataReturn();
        dataReturn.setMd5(theDigest);
        dataReturn.setMimeType("Dummy MimeType");
        dataReturn.setOutputfile(data.getOutputFileS3());
        dataReturn.setSize(data.getFileSize());
        dataReturn.setActionResponse("Dummy Action Response.");
        dataReturnList.add(dataReturn);

        fileUtils = null;
        data = null;

        return dataReturnList;
    } else {
        throw new Exception(propertyReaderLib.getPropertyValue(MessagesKeys.FAILURE.toString()));
    }
}

From source file:io.milton.http.http11.auth.DigestGenerator.java

public String encodePasswordInA1Format(String username, String realm, String password) {
    String a1 = username + ":" + realm + ":" + password;
    String a1Md5 = DigestUtils.md5Hex(a1);

    return a1Md5;
}

From source file:net.monofraps.gradlebukkit.tasks.DownloadCraftBukkit.java

private BuildArtifact prepareExecution() throws IOException, LifecycleExecutionException {
    final BuildArtifact artifact = getArtifactToDownload();

    bukkitServerJar = new File(bukkitTargetDir, "bukkit-" + artifact.getBuildNumber() + ".jar");
    final File bukkitPluginDir = new File(bukkitTargetDir, "plugins");

    if (bukkitServerJar.exists()) {
        final String localMd5 = DigestUtils.md5Hex(new FileInputStream(bukkitServerJar));
        if (!localMd5.equals(artifact.getFile().getMd5())) {
            getLogger().lifecycle("CraftBukkit MD5 sum mismatch. Going to update local copy.");
        } else {//from   w  w  w  .j a v a 2 s . c  o  m
            getLogger().lifecycle("File exists.");
            return null;
        }
    }

    if (!bukkitTargetDir.exists()) {
        if (!bukkitTargetDir.mkdir())
            throw new LifecycleExecutionException(
                    "Failed to create bukkit server directory " + bukkitTargetDir);
    }

    if (!bukkitPluginDir.exists()) {
        if (!bukkitPluginDir.mkdir())
            throw new LifecycleExecutionException(
                    "Failed to create bukkit plugin directory " + bukkitPluginDir);
    }

    return artifact;
}

From source file:br.com.pfood.util.StringUtils.java

public static String getMD5(String senha) {
    String md5 = "";
    try {// w w  w.j  a  va 2  s . c o m
        md5 = DigestUtils.md5Hex(senha.getBytes("UTF-8"));
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return md5;
}

From source file:com.cognifide.aet.job.common.collectors.screen.ScreenCollector.java

private boolean isPatternAndResultMD5Identical(byte[] screenshot) {
    if (properties.getPatternId() != null) {
        final String screenshotMD5 = DigestUtils.md5Hex(screenshot);
        final String patternMD5 = artifactsDAO.getArtifactMD5(properties, properties.getPatternId());
        return StringUtils.equalsIgnoreCase(patternMD5, screenshotMD5);
    } else {//  ww w  .ja v a 2 s . c om
        return false;
    }
}

From source file:com.googlecode.download.maven.plugin.internal.cache.DownloadCache.java

public void install(URI uri, File outputFile, String md5, String sha1, String sha512) throws Exception {
    if (md5 == null) {
        md5 = SignatureUtils.computeSignatureAsString(outputFile, MessageDigest.getInstance("MD5"));
    }//  w w w  .ja v a  2s. c  om
    if (sha1 == null) {
        sha1 = SignatureUtils.computeSignatureAsString(outputFile, MessageDigest.getInstance("SHA1"));
    }
    if (sha512 == null) {
        sha512 = SignatureUtils.computeSignatureAsString(outputFile, MessageDigest.getInstance("SHA-512"));
    }
    String entry = getEntry(uri, md5, sha1, sha512);
    if (entry != null) {
        return; // entry already here
    }
    String fileName = outputFile.getName() + '_' + DigestUtils.md5Hex(uri.toString());
    Files.copy(outputFile.toPath(), new File(this.basedir, fileName).toPath(),
            StandardCopyOption.REPLACE_EXISTING);
    // update index
    this.index.put(uri, fileName);
}

From source file:com.actelion.research.spiritcore.services.SampleListValidator.java

/**
 *  Looks for existence and uniqueness of barcode metadata and also for study id existence.
 *
 * @param csvFile. The chosen file by the user
 * @param sampleList//from  w ww  .j  a va 2s  .  co m
 * @return csv data structure
 * @throws Exception if csv data contains invalid or missing mandatory values
 */
public String[][] validate(File csvFile, Biosample sampleList) throws Exception {

    String[][] data = CSVUtils.importCsv(csvFile);

    // check if already imported
    SpiritUser user = Spirit.askForAuthentication();
    InputStream is = Files.newInputStream(Paths.get(csvFile.getAbsolutePath()));
    String checksum = DigestUtils.md5Hex(is);
    BiosampleLinker linker = new BiosampleLinker(sampleList.getBiotype().getMetadata("Checksum"));
    BiosampleQuery biosampleQuery = BiosampleQuery.createQueryForBiotype(sampleList.getBiotype());
    List<Biosample> bios = DAOBiosample.queryBiosamples(biosampleQuery, user);
    for (Biosample sample : bios) {
        String metadata = sample.getMetadataValue(linker.getBiotypeMetadata());
        if (metadata != null && metadata.equals(checksum))
            throw new Exception("This sample list has already been uploaded.");
    }
    sampleList.setMetadataValue(linker.getBiotypeMetadata(), checksum);

    // detect at which index are each column type from header line. Assuming the first line is the header
    String colName = null;
    for (int i = 0; i < data[0].length; i++) {
        colName = data[0][i].toLowerCase();
        addColumnMapping(colName, i);
    }

    // no barcode column found
    if (!columnMapping.containsKey(ColumnLabel.BARCODE.getLabel()))
        throw new Exception("No barcode column found");

    // no barcode column found
    if (columnMapping.containsKey(ColumnLabel.TYPE.getLabel()) && !checkTypeData(data))
        throw new Exception("Invalid type value. " + specificErrorMessage);

    // look for barcode duplicates
    if (columnHasDuplicates(data, getColumnIndex(ColumnLabel.BARCODE.getLabel())))
        throw new Exception("Data contains duplicate barcodes. " + specificErrorMessage);

    // check for date format dd-MMM-yyyy
    if (getColumnIndex(ColumnLabel.COLLECTION_DATE.getLabel()) >= 0) {
        checkDateFormat(data, getColumnIndex(ColumnLabel.COLLECTION_DATE.getLabel()));
    }

    // check for study existence
    if (!validateStudyIds(data))
        throw new Exception("Study id error. " + specificErrorMessage);

    return data;
}

From source file:it.univaq.incipict.profilemanager.presentation.AdministrationUserController.java

@RequestMapping(value = "/create", method = { RequestMethod.POST })
public String create(@ModelAttribute User user) {
    user.setPassword(DigestUtils.md5Hex(user.getPassword()));
    userService.create(user);/*w  w  w .jav a  2  s. c  o m*/
    return "redirect:/administration/user/list";
}

From source file:com.edgenius.wiki.integration.client.Authentication.java

private String makeTokenSignature(long tokenExpiryTime, String username, String password) {
    return DigestUtils
            .md5Hex(username + ":" + tokenExpiryTime + ":" + password + ":" + WsContants.REMEMBERME_COOKIE_KEY);
}

From source file:com.bradmcevoy.http.http11.auth.DigestGenerator.java

String encodeMethodAndUri(String httpMethod, String uri) {
    String a2 = httpMethod + ":" + uri;
    String a2Md5 = new String(DigestUtils.md5Hex(a2));
    return a2Md5;
}