List of usage examples for org.apache.commons.codec.digest DigestUtils md5
public static byte[] md5(String data)
From source file:corner.encrypt.services.impl.MD5EncryptServiceImpl.java
/** *@param src ? /* ww w. j a va 2 s . c o m*/ *@param key ,MD5? * @see corner.encrypt.EncryptService#encrypt(byte[], byte[]) */ @Override public byte[] encrypt(byte[] src, byte[] key) { return DigestUtils.md5(src); }
From source file:de.ks.flatadocdb.session.EntityUpdate.java
@Override public void prepare(Session session) { EntityDescriptor entityDescriptor = sessionEntry.getEntityDescriptor(); Object entity = sessionEntry.getObject(); checkVersionIncrement(sessionEntry.getCompletePath(), sessionEntry.getVersion()); checkNoFlushFileExists(getFlushPath()); long version = entityDescriptor.getVersion(entity); entityDescriptor.writeVersion(entity, version + 1); sessionEntry.version++;//from w w w. j a v a 2 s . c o m executeLifecycleAction(LifeCycle.PRE_UPDATE); EntityPersister persister = entityDescriptor.getPersister(); byte[] fileContents = persister.createFileContents(repository, entityDescriptor, entity); writeFlushFile(fileContents); byte[] md5 = DigestUtils.md5(fileContents); sessionEntry.setMd5(md5); checkAppendToComplete(sessionEntry.getCompletePath());//better to use Filelock if possible }
From source file:de.ks.flatadocdb.session.EntityInsertion.java
@Override public void prepare(Session session) { if (sessionEntry.getCompletePath().toFile().exists()) { throw new StaleObjectFileException("Real file already exists" + sessionEntry.getCompletePath()); }//from w w w.jav a 2 s. co m checkVersionIncrement(sessionEntry.getCompletePath(), sessionEntry.getVersion()); checkNoFlushFileExists(getFlushPath()); executeLifecycleAction(LifeCycle.PRE_PERSIST); executeLifecycleAction(LifeCycle.PRE_UPDATE); EntityPersister persister = sessionEntry.getEntityDescriptor().getPersister(); byte[] fileContents = persister.createFileContents(repository, sessionEntry.getEntityDescriptor(), sessionEntry.getObject()); writeFlushFile(fileContents); byte[] md5 = DigestUtils.md5(fileContents); sessionEntry.setMd5(md5); Path completePath = sessionEntry.getCompletePath(); sessionEntry.getEntityDescriptor().writePathInRepo(sessionEntry.getObject(), completePath); checkAppendToComplete(sessionEntry.getCompletePath());//better to use Filelock if possible }
From source file:com.bloatit.framework.utils.cache.MemoryCache.java
/** * {@inheritDoc}//from w ww.java 2s . co m * <p> * This method generates a hash of the <code>keyGenerator</code> and uses it * as a key for the element * </p> * * @param keyGenerator a String that will ba hashed to serve as a key */ @Override public void cache(final String keyGenerator, final String value) { if (keyGenerator == null || keyGenerator.isEmpty()) { throw new NonOptionalParameterException("Trying to cache with a null or empty key"); } if (value == null) { throw new NonOptionalParameterException("Trying to cache a null value"); } mcache.put(new Element(DigestUtils.md5(keyGenerator), value)); }
From source file:dtu.ds.warnme.utils.SecurityUtils.java
public static String hashMD5Base64(String stringToHash) throws UnsupportedEncodingException { byte[] bytes = stringToHash.getBytes(CHARSET_UTF8); byte[] md5bytes = DigestUtils.md5(bytes); byte[] base64bytes = Base64.encodeBase64(md5bytes); return new String(base64bytes, CHARSET_UTF8); }
From source file:com.talis.storage.s3.DirectChunkHandlerTest.java
@Test public void writeChunkUsesSuppliedServiceToStoreObject() 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().andReturn(chunk);/* w ww. jav a2s . co m*/ replay(mockService); new DirectChunkHandler(bucket, mockService).writeChunk(chunk); verify(mockService); }
From source file:com.bloatit.framework.utils.cache.MemoryCache.java
@Override public String get(final String keyGenerator) { Element element = mcache.get(DigestUtils.md5(keyGenerator)); if (element == null) { return null; }/*from w w w. ja va 2 s. c om*/ return (String) element.getValue(); }
From source file:com.eviware.loadui.util.testevents.TestEventSourceSupport.java
private void updateHash() { byte[] labelBytes = label.getBytes(); byte[] combined = new byte[labelBytes.length + data.length]; System.arraycopy(labelBytes, 0, combined, 0, labelBytes.length); System.arraycopy(data, 0, combined, labelBytes.length, data.length); hash = Base64.encodeBase64String(DigestUtils.md5(combined)); }
From source file:CipherProvider.java
/** * Create cipher for encrypt or decrypt backup content * * @param passwd passwd for encryption/*from w ww . j a va 2 s. com*/ * @param mode encrypt/decrypt mode * * @return instance of cipher */ private static Cipher getCipher(final String passwd, final int mode) { /* Derive the key, given password and salt. */ Cipher cipher = null; try { SecretKeyFactory factory = null; factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1"); String salt = "slNadZlato#%^^&(&(5?@#5166?1561?#%^^*^&54431"; // only pseudorandom salt KeySpec spec = new PBEKeySpec(passwd.toCharArray(), salt.getBytes(), 65536, 128); SecretKey tmp = factory.generateSecret(spec); SecretKey secret = new SecretKeySpec(tmp.getEncoded(), CIPHER_TYPE); // initialization vector byte[] iv = Arrays.copyOfRange(DigestUtils.md5(passwd), 0, 16); AlgorithmParameterSpec paramSpec = new IvParameterSpec(iv); // Cipher for encryption cipher = Cipher.getInstance(CIPHER_TYPE + "/CBC/PKCS5Padding"); cipher.init(mode, secret, paramSpec); } catch (Exception e) { e.printStackTrace(); //Todo implementovat } return cipher; }
From source file:ch.entwine.weblounge.common.impl.security.PasswordImpl.java
/** * Creates a new password./*from w ww . ja va 2s . co m*/ * * @param password * the password * @param type * the digest type * @throws IllegalArgumentException * if either one of <code>password</code> or <code>type</code> is * <code>null</code> */ public PasswordImpl(String password, DigestType type) { if (password == null) throw new IllegalArgumentException("Password cannot be null"); if (type == null) throw new IllegalArgumentException("Password digest type cannot be null"); this.password = password; this.passwordDigestType = type; switch (type) { case plain: try { this.md5 = new String(DigestUtils.md5(password.getBytes("utf-8"))); } catch (UnsupportedEncodingException e) { throw new IllegalStateException(e); } break; case md5: this.md5 = password; break; default: throw new IllegalArgumentException("Unknown digest type " + type); } }