List of usage examples for org.apache.commons.codec.digest DigestUtils md5
public static byte[] md5(String data)
From source file:com.qwerky.tools.foldersync.Analyser.java
private boolean requireSync(File in, File out) { if (out.exists()) { try {/*from w w w . j a v a 2 s . com*/ byte[] inmd5 = DigestUtils.md5(new FileInputStream(in)); byte[] outmd5 = DigestUtils.md5(new FileInputStream(out)); return (in.length() != out.length()) || (in.lastModified() > out.lastModified()) || !(Arrays.equals(inmd5, outmd5)); } catch (IOException ioe) { return true; } } return true; }
From source file:internal.diff.aws.service.AmazonS3ETagFileChecksumServiceImpl.java
@Override public String calculateChecksum(Path file) throws IOException { long fileSize = Files.size(file); int parts = (int) (fileSize / S3_MULTIPART_SIZE_LIMIT_IN_BYTES); parts += fileSize % S3_MULTIPART_SIZE_LIMIT_IN_BYTES > 0 ? 1 : 0; ByteBuffer checksumBuffer = ByteBuffer.allocate(parts * 16); SeekableByteChannel byteChannel = Files.newByteChannel(file); for (int part = 0; part < parts; part++) { int partSizeInBytes; if (part < parts - 1 || fileSize % S3_MULTIPART_SIZE_LIMIT_IN_BYTES == 0) { partSizeInBytes = S3_MULTIPART_SIZE_LIMIT_IN_BYTES; } else {/* www . j a v a 2s . c o m*/ partSizeInBytes = (int) (fileSize % S3_MULTIPART_SIZE_LIMIT_IN_BYTES); } ByteBuffer partBuffer = ByteBuffer.allocate(partSizeInBytes); boolean endOfFile; do { endOfFile = byteChannel.read(partBuffer) == -1; } while (!endOfFile && partBuffer.hasRemaining()); checksumBuffer.put(DigestUtils.md5(partBuffer.array())); } if (parts > 1) { return DigestUtils.md5Hex(checksumBuffer.array()) + "-" + parts; } else { return Hex.encodeHexString(checksumBuffer.array()); } }
From source file:com.logicoy.pdmp.pmpi.crypto.KeyIVGenerator.java
private void deriveKeyAndIV() { try {/*from ww w . j ava2s . c o m*/ //MessageDigest sha256 = MessageDigest.getInstance("SHA"); //MessageDigest md5 = MessageDigest.getInstance("MD5"); // Create Key and IV from password byte[] password = this.password.getBytes(Charset.forName("UTF-8")); // Key = sha256(password) this.key = DigestUtils.sha256(password); logger.info("Key length= " + this.key.length); // IV = MD5(password) //this.iv = md5.digest(this.key); this.iv = DigestUtils.md5(this.key); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.talis.storage.s3.DirectChunkHandlerTest.java
@Test(expected = IOException.class) public void exceptionThrownByServiceAreCaughtAndRethrown() throws Exception { S3Object chunk = new S3Object(key); chunk.setMd5Hash(DigestUtils.md5("Mickey Mouse is dead")); S3Service mockService = createStrictMock(S3Service.class); mockService.putObject(bucket, chunk); expectLastCall().andThrow(new S3ServiceException("TEST")); replay(mockService);// w w w. ja v a 2 s . c o m try { new DirectChunkHandler(bucket, mockService).writeChunk(chunk); } finally { verify(mockService); } }
From source file:de.ks.flatadocdb.session.dirtycheck.DirtyChecker.java
public Collection<SessionEntry> findDirty(Collection<SessionEntry> values) { return values.stream()// .filter(e -> !insertions.contains(e.getObject()))// .filter(e -> !deletions.contains(e.getObject()))// .filter(e -> {// ww w.j ava 2s . c o m EntityDescriptor entityDescriptor = e.getEntityDescriptor(); EntityPersister persister = entityDescriptor.getPersister(); byte[] fileContents = persister.createFileContents(repository, entityDescriptor, e.getObject()); byte[] md5 = DigestUtils.md5(fileContents); boolean dirty = !Arrays.equals(md5, e.getMd5()); if (dirty) { log.debug("Found dirty entity {} {}", e.getObject(), e.getFileName()); } else { log.trace("Non-dirty entity {} {}", e.getObject(), e.getFileName()); } return dirty; }).collect(Collectors.toSet()); }
From source file:com.github.aynu.mosir.core.standard.util.CodecHelper.java
/** * MD5/*from w ww. ja va2s . c o m*/ * <dl> * <dt>? * <dd>MD5????? * </dl> * @param data * @return ?? */ public static byte[] md5(final byte[] data) { return DigestUtils.md5(data); }
From source file:ZipSourceCallable.java
@Override public String invoke(File f, VirtualChannel channel) throws IOException { String sourceFilePath = workspace.getRemote(); // Create a temp file to zip into so we do not zip ourselves File tempFile = File.createTempFile(f.getName(), null, null); try (OutputStream zipFileOutputStream = new FileOutputStream(tempFile)) { try (ZipOutputStream out = new ZipOutputStream(zipFileOutputStream)) { zipSource(workspace, sourceFilePath, out, sourceFilePath); }/* www. ja va 2 s .c o m*/ } catch (IOException e) { throw e; } catch (Exception e) { throw new IOException(e); } // Copy zip to the location we expect it to be in FileUtils.copyFile(tempFile, f); try { tempFile.delete(); } catch (Exception e) { // If this fails, the file will just be cleaned up // by the system later. We are just trying to be // good citizens here. } String zipFileMD5; // Build MD5 checksum before returning try (InputStream zipFileInputStream = new FileInputStream(f)) { zipFileMD5 = new String(encodeBase64(DigestUtils.md5(zipFileInputStream)), Charsets.UTF_8); return zipFileMD5; } }
From source file:com.talis.storage.s3.DirectChunkHandlerTest.java
@Test public void writeChunkReturnsObjectReturnedByService() throws Exception { S3Object chunk = new S3Object(key); S3Object written = new S3Object(key); written.setMd5Hash(DigestUtils.md5("Mickey Mouse is dead")); S3Service mockService = createStrictMock(S3Service.class); mockService.putObject(bucket, chunk); expectLastCall().andReturn(written); replay(mockService);//from w ww . ja va2 s . c om assertSame(written, new DirectChunkHandler(bucket, mockService).writeChunk(chunk)); verify(mockService); }
From source file:ch.entwine.weblounge.common.impl.security.PasswordImpl.java
/** * {@inheritDoc}//from w w w .jav a 2s . c o m * * @see java.lang.Object#equals(java.lang.Object) */ @Override public boolean equals(Object o) { if (!(o instanceof Password)) return false; Password pw = (Password) o; DigestType digestType = pw.getDigestType(); switch (digestType) { case md5: return md5.equals(pw.getPassword()); case plain: try { return md5.equals(DigestUtils.md5(pw.getPassword().getBytes("utf-8"))); } catch (UnsupportedEncodingException e) { throw new IllegalStateException(e); } default: throw new IllegalStateException("Found unknown digest type " + digestType); } }
From source file:com.dragoniade.encrypt.EncryptionHelper.java
private static byte[] getSeed(String seed) { byte[] xor = { -35, -54, -58, -91, -69, 23, 88, 103, -107, -95, 50, -100, 123, 57, -22, -87 }; byte[] byteKey = DigestUtils.md5(seed); for (int i = 0; i < byteKey.length; i++) { byteKey[i] = (byte) (byteKey[i] ^ xor[i]); }/*w w w . ja va 2 s . co m*/ return byteKey; }