List of usage examples for java.security MessageDigest update
public final void update(ByteBuffer input)
From source file:com.continusec.client.ObjectHash.java
private static final byte[] hashNull() throws ContinusecException { MessageDigest d = DigestUtils.getSha256Digest(); d.update((byte) 'n'); return d.digest(); }
From source file:com.continusec.client.ObjectHash.java
private static final byte[] hashArray(JsonArray a, String r) throws ContinusecException { MessageDigest d = DigestUtils.getSha256Digest(); d.update((byte) 'l'); for (JsonElement e : a) { d.update(objectHashWithRedaction(e, r)); }//w w w. j ava2 s. c o m return d.digest(); }
From source file:com.continusec.client.ObjectHash.java
private static final byte[] hashBoolean(boolean b) throws ContinusecException { MessageDigest d = DigestUtils.getSha256Digest(); d.update((byte) 'b'); if (b) {/* w w w . j a va 2 s.c o m*/ d.update((byte) '1'); } else { d.update((byte) '0'); } return d.digest(); }
From source file:com.dtolabs.rundeck.core.execution.commands.ScriptURLCommandInterpreter.java
private static String hashURL(final String url) { try {// w w w . j av a 2s. c o m MessageDigest digest = MessageDigest.getInstance("SHA-1"); digest.reset(); digest.update(url.getBytes(Charset.forName("UTF-8"))); return new String(Hex.encodeHex(digest.digest())); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return Integer.toString(url.hashCode()); }
From source file:com.seleniumtests.util.StringUtility.java
public static String md5(final String str) { if (str == null) { return null; }//from w w w.jav a 2 s . co m MessageDigest messageDigest = null; try { messageDigest = MessageDigest.getInstance("MD5"); messageDigest.reset(); messageDigest.update(str.getBytes("UTF-8")); } catch (UnsupportedEncodingException | NoSuchAlgorithmException e) { logger.error(e); return str; } byte[] byteArray = messageDigest.digest(); return toHexString(byteArray); }
From source file:com.continusec.client.ObjectHash.java
private static final byte[] hashObject(JsonObject o, String r) throws ContinusecException { ArrayList<byte[]> entries = new ArrayList<byte[]>(); for (Map.Entry<String, JsonElement> e : o.entrySet()) { entries.add(ArrayUtils.addAll(hashString(e.getKey(), r), objectHashWithRedaction(e.getValue(), r))); }/*from w ww. j ava 2s .c om*/ Collections.sort(entries, ByteArrayComparator.getInstance()); MessageDigest d = DigestUtils.getSha256Digest(); d.update((byte) 'd'); for (byte[] b : entries) { d.update(b); } return d.digest(); }
From source file:com.arrow.acn.client.utils.MD5Util.java
public static byte[] calcMD5Checksum(Path path) throws NoSuchAlgorithmException, IOException { MessageDigest md = MessageDigest.getInstance("MD5"); try (SeekableByteChannel sbc = Files.newByteChannel(path)) { ByteBuffer buf = ByteBuffer.allocateDirect(BUFFER_SIZE); while (sbc.read(buf) > 0) { buf.flip();//ww w.j av a2 s .c o m md.update(buf); buf.clear(); } } return md.digest(); }
From source file:fr.cnes.sitools.security.SecurityUtil.java
/** * Encryption with OpenLDAP digest md5 algorithm (<> HTTP digest MD5) * /* w w w . j a va 2s .c o m*/ * @param password * user password * @return encrypted key */ public static String openldapDigestMd5(final String password) { String base64; try { MessageDigest digest = MessageDigest.getInstance("MD5"); digest.update(password.getBytes()); // base64 = new BASE64Encoder().encode(digest.digest()); // base64 = fr.cnes.sitools.util.Base64Sun.encode(digest.digest()); // base64 = fr.cnes.sitools.util.Base64.encodeBytes(digest.digest()); base64 = new String(org.apache.commons.codec.binary.Base64.encodeBase64(digest.digest())); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } return OPENLDAP_MD5_PREFIX + base64; }
From source file:com.algodefu.yeti.md5.MD5HashGenerator.java
public static String generateKeyByObject(Object object) { MessageDigest m = null; try {/*from w w w .j ava 2s . c o m*/ m = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } m.reset(); //m.update(objectToByteArray(object)); m.update(SerializationUtils.serialize((Serializable) object)); byte[] digest = m.digest(); BigInteger bigInt = new BigInteger(1, digest); String hashtext = bigInt.toString(16); while (hashtext.length() < 32) { hashtext = "0" + hashtext; } return hashtext; }
From source file:com.linuxbox.enkive.docstore.mongo.FileDocStoreServiceTest.java
@BeforeClass public static void setUpClass() throws Exception { docStoreService = new ConvenienceFileDocStoreService(TestingConstants.MONGODB_TEST_FILEBASE, TestingConstants.MONGODB_TEST_DATABASE, FILE_COLLECTION); docStoreService.startup();/*from ww w . j a v a 2 s . c o m*/ testDocument = new StringDocument(testString, "text/plain", "txt", "testFile.txt", MimeUtil.ENC_7BIT); MessageDigest messageDigest = getPrimedMessageDigest(testDocument); messageDigest.update(testData); testDocumentHash = messageDigest.digest(); }