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:mx.edu.ittepic.AEEcommerce.servlets.Login.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request//from  w  ww .j  a  va2  s  .com
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("application/json;charset=UTF-8");
    response.setHeader("Cache-Control", "no-store");
    PrintWriter out = response.getWriter();

    CartBean2Remoto ejb = (CartBean2Remoto) request.getSession().getAttribute("ejbsesion");
    String user = request.getParameter("usuario");
    String password = request.getParameter("password");
    System.out.println("password anterior:" + password);
    password = DigestUtils.md5Hex(password);
    System.out.println("password nueva:" + password);
    if (ejb == null) {
        try {
            InitialContext ic = new InitialContext();
            ejb = (CartBean2Remoto) ic.lookup("java:comp/env/ejbs/CartBean2");
            GsonBuilder builder = new GsonBuilder();
            Gson gson = builder.create();
            //password= DigestUtils.md5Hex(password);
            Message m = gson.fromJson(ejb.login(user, password), Message.class);
            if (m.getCode() == 200) {
                request.getSession().setAttribute("ejbsesion", ejb);

            }
            out.print(new GsonBuilder().create().toJson(m));
        } catch (NamingException e) {
            out.print(e.toString());
        }
    }
}

From source file:com.norconex.collector.http.checksum.impl.DefaultHttpDocumentChecksummer.java

@Override
public String createChecksum(HttpDocument document) {
    // If field is not specified, perform checksum on whole text file.
    if (StringUtils.isNotBlank(field)) {
        String value = document.getMetadata().getString(field);
        if (StringUtils.isNotBlank(value)) {
            String checksum = DigestUtils.md5Hex(value);
            LOG.debug("Document checksum: " + checksum);
            return checksum;
        }/*www  . j  a  v  a 2s  .  c o  m*/
        return null;
    }
    try {
        FileInputStream is = new FileInputStream(document.getLocalFile());
        String checksum = DigestUtils.md5Hex(is);
        LOG.debug("Document checksum: " + checksum);
        is.close();
        return checksum;
    } catch (IOException e) {
        throw new HttpCollectorException("Cannot create checksum on : " + document.getLocalFile(), e);
    }
}

From source file:act.installer.reachablesexplorer.MoleculeRenderer.java

public File getRenderingFile(String inchi) {
    String md5 = DigestUtils.md5Hex(inchi);
    String postfix = String.format("-%s%s", md5, PNG_EXTENSION);

    String renderingFilename = String.join("", "molecule", postfix);
    return Paths.get(this.assetLocation.getPath(), renderingFilename).toFile();
}

From source file:com.compomics.pladipus.controller.setup.InstallActiveMQ.java

private void downloadActiveMQ() throws IOException, ZipException {

    //File downloadFile = PladipusFileDownloadingService.downloadFile(link, activeMQFolder);

    if (!activeMQFolder.exists() & !activeMQFolder.mkdirs()) {
        throw new IOException("could not make install folder");
    }/*from  w w  w .  java2 s  .c  o m*/

    URL website = new URL(link);
    Path downloadFile = Files.createTempFile("activemqdownload", null);
    try (ReadableByteChannel rbc = Channels.newChannel(website.openStream());
            FileOutputStream fos = new FileOutputStream(downloadFile.toFile())) {
        //todo replace with loop and replace Long.MAX_VALUE with buffer size?
        if (fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE) != 0) {
            try (FileInputStream fis = new FileInputStream(downloadFile.toFile())) {
                if (DigestUtils.md5Hex(fis).equals("4b844f588672e6616bd6f006253d6148")) {
                    ZipFile zipFile = new ZipFile(downloadFile.toFile());
                    zipFile.extractAll(activeMQFolder.getPath());

                } else {
                    throw new IOException("md5 digest did not match, aborting");
                }
            }
        }
    }
}

From source file:cn.vlabs.clb.server.web.AccessTokenService.java

private String generateToken(int appid, int docid, int version, String publicKey) {
    try {//  w w w.ja v  a  2  s  .  c o m
        String raw = appid + "#" + docid + "#" + version;
        byte[] b = Base64.encodeBase64(raw.getBytes(), true);
        String firstKey = new String(b, "UTF-8");
        String secondLevel = publicKey.substring(0, 10) + firstKey + publicKey.substring(11);
        String token = DigestUtils.md5Hex(secondLevel);
        add(token, appid, docid, version);
        return token;
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:com.miyue.util.EncoderUtil.java

/**
 * /* w w  w.  j av a  2  s . c o  m*/
 * @param str
 * @return ?MD5
 * @throws Exception
 */
public static String EncoderByMd5(String str) throws Exception {
    return DigestUtils.md5Hex(str.getBytes());
}

From source file:com.thoughtworks.go.server.view.artifacts.ArtifactDirectoryChooser.java

public File temporaryConsoleFile(LocatableEntity locatableEntity) {
    return new File("data/console", format("%s.log", DigestUtils.md5Hex(locatableEntity.entityLocator())));
}

From source file:com.petalmd.armor.authentication.backend.simple.SettingsBasedAuthenticationBackend.java

@Override
public User authenticate(final com.petalmd.armor.authentication.AuthCredentials authCreds)
        throws AuthException {
    final String user = authCreds.getUsername();
    final String clearTextPassword = authCreds.getPassword() == null ? null
            : new String(authCreds.getPassword());
    authCreds.clear();//from ww w.j a  v  a 2 s . co m

    String digest = settings.get(ConfigConstants.ARMOR_AUTHENTICATION_SETTINGSDB_DIGEST, null);
    final String storedPasswordOrDigest = settings
            .get(ConfigConstants.ARMOR_AUTHENTICATION_SETTINGSDB_USER + user, null);

    if (!StringUtils.isEmpty(clearTextPassword) && !StringUtils.isEmpty(storedPasswordOrDigest)) {

        String passwordOrHash = clearTextPassword;

        if (digest != null) {

            digest = digest.toLowerCase();

            switch (digest) {

            case "sha":
            case "sha1":
                passwordOrHash = DigestUtils.sha1Hex(clearTextPassword);
                break;
            case "sha256":
                passwordOrHash = DigestUtils.sha256Hex(clearTextPassword);
                break;
            case "sha384":
                passwordOrHash = DigestUtils.sha384Hex(clearTextPassword);
                break;
            case "sha512":
                passwordOrHash = DigestUtils.sha512Hex(clearTextPassword);
                break;

            default:
                passwordOrHash = DigestUtils.md5Hex(clearTextPassword);
                break;
            }

        }

        if (storedPasswordOrDigest.equals(passwordOrHash)) {
            return new User(user);
        }

    }

    throw new AuthException("No user " + user + " or wrong password (digest: "
            + (digest == null ? "plain/none" : digest) + ")");
}

From source file:cc.recommenders.nativelibs.NativeLibLoaderTest.java

private void assertCorrectFile(String inFileName) {
    FileInputStream fis = null;/*from ww  w  .  j a  va  2s  . c  o m*/
    FileInputStream fos = null;
    try {
        fis = new FileInputStream(new File(lib, inFileName));
        String md5in = DigestUtils.md5Hex(fis);
        fis.close();

        String outFileName = sut.copyLibraryToTempFile("jsmile");

        fos = new FileInputStream(new File(outFileName));
        String md5out = DigestUtils.md5Hex(fos);
        fos.close();

        assertEquals(md5in, md5out);
    } catch (IOException e) {
        fail();
    } finally {
        IOUtils.closeQuietly(fis);
        IOUtils.closeQuietly(fos);
    }
}

From source file:com.github.dactiv.fear.commons.AuthCoder.java

/**
 * //from w w w .j av a2  s .  c o m
 *
 * @param value           ?
 * @param key             
 * @param randomKeyLength ? ? 0-32????
 *                        ???iv??
 *                        ? = 16  randomKeyLength  0 ??
 * @param encoding        ?
 * @return ?
 */
public static String decode(String value, String key, int randomKeyLength, String encoding)
        throws UnsupportedEncodingException {

    key = DigestUtils.md5Hex(key.getBytes());

    String keya = DigestUtils.md5Hex(StringUtils.substring(key, 0, 16).getBytes());
    String keyb = DigestUtils.md5Hex(StringUtils.substring(key, 16, 16 + 16).getBytes());
    String keyc = randomKeyLength > 0 ? StringUtils.substring(value, 0, randomKeyLength) : "";

    String cryptKey = keya + DigestUtils.md5Hex((keya + keyc).getBytes());
    int cryptKeyLen = cryptKey.length();

    value = new String(Base64.decodeBase64((StringUtils.substring(value, randomKeyLength))), encoding);
    int stringLen = value.length();

    List<Integer> rndKey = new ArrayList<>();

    StringBuilder result = new StringBuilder();

    Integer[] box = new Integer[256];
    for (int i = 0; i < box.length; i++) {
        box[i] = i;
    }

    for (int i = 0; i <= 255; i++) {
        rndKey.add((int) cryptKey.charAt(i % cryptKeyLen));
    }

    for (int j = 0, i = 0; i < 256; i++) {
        j = (j + box[i] + rndKey.get(i)) % 256;
        int tmp = box[i];
        box[i] = box[j];
        box[j] = tmp;
    }

    for (int k = 0, j = 0, i = 0; i < stringLen; i++) {
        k = (k + 1) % 256;
        j = (j + box[k]) % 256;
        int tmp = box[k];
        box[k] = box[j];
        box[j] = tmp;
        int a = (int) value.charAt(i);
        int b = box[(box[k] + box[j]) % 256];
        char r = (char) (a ^ b);
        result.append(r);
    }

    if ((NumberUtils.toInt(StringUtils.substring(result.toString(), 0, 10), -1) == 0
            || NumberUtils.toInt(StringUtils.substring(result.toString(), 0, 10), 0)
                    - System.currentTimeMillis() / 1000 > 0)
            && StringUtils.substring(result.toString(), 10, 10 + 16)
                    .equals(StringUtils.substring(
                            DigestUtils
                                    .md5Hex((StringUtils.substring(result.toString(), 26) + keyb).getBytes()),
                            0, 16))) {
        return StringUtils.substring(result.toString(), 26);
    } else {
        return "";
    }
}