List of usage examples for org.apache.commons.codec.digest DigestUtils md5
public static byte[] md5(String data)
From source file:net.straylightlabs.tivolibre.TivoStreamChunk.java
public byte[] getMetadataKey(String mak) { byte[] prefixBytes = MEDIA_MAK_PREFIX.getBytes(); byte[] makBytes = mak.getBytes(); byte[] bytes = new byte[prefixBytes.length + makBytes.length]; System.arraycopy(prefixBytes, 0, bytes, 0, prefixBytes.length); System.arraycopy(makBytes, 0, bytes, prefixBytes.length, makBytes.length); byte[] md5 = DigestUtils.md5(bytes); byte[] metaKey = new byte[32]; for (int i = 0; i < md5.length; i++) { metaKey[i * 2] = (byte) LOOKUP_STRING.charAt((md5[i] >> 4) & 0xf); metaKey[i * 2 + 1] = (byte) LOOKUP_STRING.charAt(md5[i] & 0xf); }//from w w w. ja v a 2 s . com return getKey(new String(metaKey)); }
From source file:net.ymate.framework.core.util.WebUtils.java
/** * (IP?)//from w w w . j av a2 s . c o m * * @param request HttpServletRequest * @param dataStr * @return ? * @throws Exception ? */ public static String encryptStr(HttpServletRequest request, String dataStr) throws Exception { return Base64.encodeBase64URLSafeString(CodecUtils.DES.encrypt(dataStr.getBytes(), DigestUtils.md5(request.getRemoteAddr() + request.getHeader("User-Agent")))); }
From source file:net.ymate.framework.core.util.WebUtils.java
public static String encryptStr(HttpServletRequest request, byte[] bytes) throws Exception { return Base64.encodeBase64URLSafeString(CodecUtils.DES.encrypt(bytes, DigestUtils.md5(request.getRemoteAddr() + request.getHeader("User-Agent")))); }
From source file:net.ymate.framework.core.util.WebUtils.java
/** * //from www. j av a2 s. co m * * @param dataStr * @param key * @return ? * @throws Exception ? */ public static String encryptStr(String dataStr, String key) throws Exception { return Base64.encodeBase64URLSafeString(CodecUtils.DES.encrypt(dataStr.getBytes(), DigestUtils.md5(key))); }
From source file:net.ymate.framework.core.util.WebUtils.java
/** * (IP?)//from w w w . j a v a2 s.c om * * @param request HttpServletRequest * @param dataStr * @return ? * @throws Exception ? */ public static String decryptStr(HttpServletRequest request, String dataStr) throws Exception { return new String(CodecUtils.DES.decrypt(Base64.decodeBase64(dataStr), DigestUtils.md5(request.getRemoteAddr() + request.getHeader("User-Agent")))); }
From source file:net.ymate.framework.core.util.WebUtils.java
public static byte[] decryptStr(HttpServletRequest request, byte[] bytes) throws Exception { return CodecUtils.DES.decrypt(Base64.decodeBase64(bytes), DigestUtils.md5(request.getRemoteAddr() + request.getHeader("User-Agent"))); }
From source file:net.ymate.framework.core.util.WebUtils.java
/** * //from ww w . j a v a 2s . c o m * * @param dataStr * @param key * @return ? * @throws Exception ? */ public static String decryptStr(String dataStr, String key) throws Exception { return new String(CodecUtils.DES.decrypt(Base64.decodeBase64(dataStr), DigestUtils.md5(key))); }
From source file:nl.salp.warcraft4j.hash.Md5Hash.java
@Override public byte[] hash(byte[] data) { return DigestUtils.md5(data); }
From source file:org.apache.abdera.ext.oauth.OAuthScheme.java
private String sign(String method, String baseString, Certificate cert) throws AuthenticationException { if (method.equalsIgnoreCase("HMAC-MD5") || method.equalsIgnoreCase("HMAC-SHA1")) { try {// w w w. j av a 2 s . c o m String[] tokens = method.split("-"); String methodName = tokens[0].substring(0, 1).toUpperCase() + tokens[0].substring(1).toLowerCase() + tokens[1]; KeyGenerator kg = KeyGenerator.getInstance(methodName); Mac mac = Mac.getInstance(kg.getAlgorithm()); mac.init(kg.generateKey()); byte[] result = mac.doFinal(baseString.getBytes()); return new String(Base64.encodeBase64(result)); } catch (Exception e) { throw new AuthenticationException(e.getMessage(), e); } } else if (method.equalsIgnoreCase("md5")) { return new String(Base64.encodeBase64(DigestUtils.md5(baseString))); } else if (method.equalsIgnoreCase("sha1")) { return new String(Base64.encodeBase64(DigestUtils.sha(baseString))); } else if (method.equalsIgnoreCase("RSA-SHA1")) { if (cert == null) { throw new AuthenticationException("a cert is mandatory to use SHA1 with RSA"); } try { Cipher cipher = Cipher.getInstance("SHA1withRSA"); cipher.init(Cipher.ENCRYPT_MODE, cert); byte[] result = cipher.doFinal(baseString.getBytes()); return new String(Base64.encodeBase64(result)); } catch (Exception e) { throw new AuthenticationException(e.getMessage(), e); } } else { throw new AuthenticationException("unsupported algorithm method: " + method); } }
From source file:org.apache.ace.authentication.processor.password.PasswordAuthenticationProcessor.java
/** * Hashes a given password using the current set hash method. * // w w w . j a v a2s . c o m * @param password the password to hash, should not be <code>null</code>. * @return the hashed password, never <code>null</code>. */ private Object hashPassword(Object password) { if ("none".equalsIgnoreCase(m_passwordHashMethod)) { // Very special ROT26 hashing method... return password; } if ("md5".equalsIgnoreCase(m_passwordHashMethod)) { if (password instanceof byte[]) { return DigestUtils.md5((byte[]) password); } return DigestUtils.md5((String) password); } if ("sha1".equalsIgnoreCase(m_passwordHashMethod)) { if (password instanceof byte[]) { return DigestUtils.sha((byte[]) password); } return DigestUtils.sha((String) password); } if ("sha256".equalsIgnoreCase(m_passwordHashMethod)) { if (password instanceof byte[]) { return DigestUtils.sha256((byte[]) password); } return DigestUtils.sha256((String) password); } if ("sha384".equalsIgnoreCase(m_passwordHashMethod)) { if (password instanceof byte[]) { return DigestUtils.sha384((byte[]) password); } return DigestUtils.sha384((String) password); } if ("sha512".equalsIgnoreCase(m_passwordHashMethod)) { if (password instanceof byte[]) { return DigestUtils.sha512((byte[]) password); } return DigestUtils.sha512((String) password); } return password; }