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:io.stallion.services.PermaCache.java

public static void set(String key, String contents) {
    cache.put(key, contents);//from   ww  w  .  j  a  va 2s  .  c o  m
    if (!empty(getCacheFolder())) {
        File file = new File(getCacheFolder() + "/" + DigestUtils.md5Hex(key));
        try {
            FileUtils.write(file, contents, "utf-8");
        } catch (IOException e) {
            Log.exception(e, "Error writing file to cache: " + file.toString());
        }
    }
}

From source file:alluxio.cli.fs.command.ChecksumCommandIntegrationTest.java

/**
 * Tests md5 checksum calculation./*ww  w .j a v  a  2 s  .c  om*/
 */
@Test
public void checksum() throws Exception {
    FileSystemTestUtils.createByteFile(mFileSystem, "/testFile", WriteType.MUST_CACHE, 10);
    mFsShell.run("checksum", "/testFile");
    String str = mOutput.toString();
    String[] splitString = str.split("\\s+");

    byte[] data = BufferUtils.getIncreasingByteArray(10);
    try {
        String expectedMd5 = DigestUtils.md5Hex(data);
        Assert.assertEquals(splitString[1], expectedMd5);
    } catch (Exception e) {
        Assert.fail("md5cksum failure not expected: " + e.getMessage());
    }
}

From source file:br.mack.facade.ApiMarvelFacade.java

public Thumbnail obterUrlImagem(Integer idPersonagem) throws IOException {
    Thumbnail tn = null;//from   w  ww  .j  ava2 s .co m
    long ts = Calendar.getInstance().getTimeInMillis();

    HttpClient cliente = HttpClients.createDefault();
    String stringToHash = ts + PRIVATE_KEY + PUBLIC_KEY;
    String hash = DigestUtils.md5Hex(stringToHash);

    String url = String.format("http://gateway.marvel.com:80/v1/public/characters/%d?ts=%d&apikey=%s&hash=%s",
            idPersonagem, ts, PUBLIC_KEY, hash);
    HttpGet httpget = new HttpGet(url);
    HttpResponse response = null;
    response = cliente.execute(httpget);
    System.out.println(response.getStatusLine());
    HttpEntity entity = response.getEntity();
    if (entity != null) {
        InputStream instream = entity.getContent();
        BufferedReader reader = new BufferedReader(new InputStreamReader(instream));
        StringBuilder out = new StringBuilder();
        String line;
        while ((line = reader.readLine()) != null) {
            out.append(line);
        }
        String result = out.toString();
        Pattern p1 = Pattern.compile("\"thumbnail\":\\{[^{}]+\\}");
        Pattern p2 = Pattern.compile("\\{[^{}]+\\}");
        if (result.contains("thumbnail")) {
            Matcher matcher = p1.matcher(result);
            boolean find = matcher.find();
            if (find) {
                String g1 = matcher.group();
                matcher = p2.matcher(g1);
                find = matcher.find();
                if (find) {
                    ObjectMapper om = new ObjectMapper();
                    tn = om.readValue(matcher.group(), Thumbnail.class);
                }
            }
        }
        reader.close();
        instream.close();
    }

    return tn;

}

From source file:com.github.mefi.jkuuza.model.BodyContent.java

public BodyContent(String url, String bodyHtml, String bodyText) {

    this.docType = "bodyContent";
    this.hash = DigestUtils.md5Hex(bodyHtml);
    this.url = url;
    this.bodyHtml = bodyHtml;
    this.bodyText = bodyText;
    this.date = getFormatedDateTime();

    this.id = createId(url, hash);
}

From source file:com.daraf.projectdarafprotocol.Mensaje.java

public void setCuerpo(Cuerpo cuerpo) {
    this.cuerpo = cuerpo;
    this.cabecera.setLongitudCuerpo(String.valueOf(this.cuerpo.asTexto().length()));
    this.cabecera.setVerificacion(DigestUtils.md5Hex(this.cuerpo.asTexto()));

}

From source file:com.beginner.core.utils.MD5.java

/**
 * verify(????) <br />/*  w ww .  ja  v a  2s .  c  o m*/
 * (???  ?)
 * @param text ???
 * @param sign ??
 * @param key 
 * @param input_charset ??
 * @return
 * boolean ??
 * @exception
 * @since 1.0.0
 */
public static boolean verify(String text, String sign, String key, String input_charset) {
    text = text + key;
    String mysign = DigestUtils.md5Hex(getContentBytes(text, input_charset));
    if (mysign.equals(sign)) {
        return true;
    } else {
        return false;
    }
}

From source file:com.msds.km.service.Impl.PrizeCordServiceImpl.java

@Override
@Transactional(rollbackFor = Exception.class)
public String generate(String sn, String phone, String license, String model, Date expiryDate, String openid) {
    StringBuffer sb = new StringBuffer(sn);
    sb.append(phone);/* w ww  .java 2  s.  com*/
    sb.append(System.currentTimeMillis());
    String prizeCord = DigestUtils.md5Hex(sb.toString()).substring(8, 24).toUpperCase();
    PrizeCordEntity prizeCordEntity = new PrizeCordEntity();
    prizeCordEntity.setSn(prizeCord);
    prizeCordEntity.setActivitySn(sn);
    prizeCordEntity.setExpiryDate(expiryDate);
    prizeCordEntity.setModel(model);
    prizeCordEntity.setLicense(license);
    prizeCordEntity.setOpenid(openid);
    prizeCordEntity.setPhone(phone);
    prizeCordEntity.setState(1);
    prizeCordEntity.setCreateDate(new Date());
    ActivityEntity activityEntity = activityMapper.lockBySn(sn);
    if (activityEntity.getQuantity() < activityEntity.getCount()) {
        prizeCordMapper.add(prizeCordEntity);
        activityMapper.quantityIncr(sn);
        return prizeCord;
    }
    return null;
}

From source file:io.muic.ooc.webapp.servlet.EditServlet.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String username = request.getParameter("usernameEdit");
    String password = request.getParameter("passwordEdit");
    System.out.println("YEAHHHHHHHH" + username);
    System.out.println("YEAHHHHHHHH" + password);
    String digest = DigestUtils.md5Hex(password);
    try {//from   w  w w  . j ava  2  s.  c o  m
        mySQLService.editDataBase(username, digest);
    } catch (Exception e) {

    }
    response.sendRedirect("/");
}

From source file:com.glaf.activiti.util.ProcessUtils.java

public static String getImagePath(ProcessDefinition processDefinition) {
    String resourceName = processDefinition.getDiagramResourceName();
    if (resourceName != null) {
        String ext = getFileExt(resourceName);
        String md5_hex = DigestUtils.md5Hex(resourceName);
        String imagePath = processDefinition.getDeploymentId() + "_" + md5_hex + "." + ext;
        return imagePath;
    }// w  w w. java  2s . com
    return null;
}

From source file:gr.abiss.calipso.wicket.components.icons.GravatarModel.java

public GravatarModel(IModel/*<String>*/ model, int hsize) {
    email = (String) model.getObject();
    gravatarKey = DigestUtils.md5Hex(email);
    this.hsize = hsize;
}