List of usage examples for org.apache.commons.codec.digest MessageDigestAlgorithms MD5
String MD5
To view the source code for org.apache.commons.codec.digest MessageDigestAlgorithms MD5.
Click Source Link
From source file:algoritmorsa_md5.MD5.java
/** * @param args the command line arguments *///from w ww .j a v a 2s. com public static void main(String[] args) throws NoSuchAlgorithmException { // TODO code application logic here MessageDigest md = MessageDigest.getInstance(MessageDigestAlgorithms.MD5); md.update("yesica".getBytes()); byte[] digest = md.digest(); for (byte b : digest) { System.out.println(Integer.toHexString(0xFF & b)); } System.out.println(); byte[] encoded = Base64.encodeBase64(digest); System.out.println(new String(encoded)); }
From source file:it.infn.mw.iam.util.ssh.RSAPublicKeyUtils.java
private static String buildMD5Fingerprint(String key) throws InvalidSshKeyException { String fingerprint = null;/*from w ww .ja va2 s. co m*/ try { byte[] decodedKey = Base64.getDecoder().decode(key); byte[] digest = MessageDigest.getInstance(MessageDigestAlgorithms.MD5).digest(decodedKey); fingerprint = Hex.encodeHexString(digest); } catch (Exception e) { throw new InvalidSshKeyException("Error during fingerprint generation: RSA key is not base64 encoded", e); } return fingerprint; }
From source file:com.redhat.victims.plugin.ant.FileStub.java
/** * Hash the file to get a "unique" key for caching * //from w w w . j a v a 2 s .co m * @param file * file to hash * @param name * canonical file name * @return name + md5 hash of file * @throws VictimsException */ private static String hashFile(File file, String name) throws VictimsException { InputStream fis = null; try { fis = new FileInputStream(file); byte[] buffer = new byte[1024]; MessageDigest mda = MessageDigest.getInstance(MessageDigestAlgorithms.MD5); int numRead; do { numRead = fis.read(buffer); if (numRead > 0) { mda.update(buffer, 0, numRead); } } while (numRead != -1); return name + Hex.encodeHexString(mda.digest()); } catch (NoSuchAlgorithmException e) { throw new VictimsException(String.format("Could not hash file: %s", name), e); } catch (IOException io) { throw new VictimsException(String.format("Could not open file: %s", name), io); } finally { IOUtils.closeQuietly(fis); } }
From source file:com.redhat.victims.plugin.eclipse.FileStub.java
/** * Hash the file to get a "unique" key for caching * //w w w . j a v a2 s . c o m * @param file * file to hash * @param name * canonical file name * @return name + md5 hash of file * @throws VictimsException */ private static String hashFile(File file, String name) throws VictimsException { InputStream fis = null; try { fis = new FileInputStream(file); byte[] buffer = new byte[1024]; MessageDigest mda = MessageDigest.getInstance(MessageDigestAlgorithms.MD5); int numRead; do { numRead = fis.read(buffer); if (numRead > 0) { mda.update(buffer, 0, numRead); } } while (numRead != -1); return name + Hex.encodeHexString(mda.digest()); } catch (NoSuchAlgorithmException e) { throw new VictimsException(String.format("Could not hash file: %s", name), e); } catch (IOException io) { throw new VictimsException(String.format("Could not open file: %s", name), io); } finally { IOUtils.closeQuietly(fis); } }
From source file:com.aoppp.gatewaysdk.internal.hw.DigestUtils2.java
/** * Returns an MD5 MessageDigest./*from w w w.ja v a 2s .c om*/ * * @return An MD5 digest instance. * @throws IllegalArgumentException * when a {@link NoSuchAlgorithmException} is caught, which should never happen because MD5 is a * built-in algorithm * @see MessageDigestAlgorithms#MD5 */ public static MessageDigest getMd5Digest() { return getDigest(MessageDigestAlgorithms.MD5); }
From source file:com.blackducksoftware.integration.phonehome.PhoneHomeRequestBodyBuilder.java
public String md5Hash(final String string) throws NoSuchAlgorithmException, UnsupportedEncodingException { final MessageDigest md = MessageDigest.getInstance(MessageDigestAlgorithms.MD5); final byte[] hashedBytes = md.digest(string.getBytes("UTF-8")); return DigestUtils.md5Hex(hashedBytes); }
From source file:edu.umkc.sce.VpQuery.java
byte[] getResultHash(ResultSet results) { MessageDigest md = null;/*from ww w . ja v a 2s .co m*/ ; try { md = MessageDigest.getInstance(MessageDigestAlgorithms.MD5); } catch (NoSuchAlgorithmException e) { // TODO Auto-generated catch block e.printStackTrace(); } while (results.hasNext()) { QuerySolution sol = results.nextSolution(); Iterator<String> col = sol.varNames(); while (col.hasNext()) { md.update(sol.get(col.next()).asNode().toString().getBytes()); } } return md.digest(); }