List of usage examples for com.liferay.portal.kernel.util DigesterUtil digest
public static String digest(String algorithm, String... text)
From source file:com.liferay.petra.encryptor.Encryptor.java
License:Open Source License
/** * @deprecated As of 1.0.0, replaced by {@link * DigesterUtil#digest(String, String...)} *//*www . ja va 2 s . com*/ @Deprecated public static String digest(String algorithm, String text) { return DigesterUtil.digest(algorithm, text); }
From source file:com.liferay.util.Encryptor.java
License:Open Source License
public static String digest(String algorithm, String text) { return DigesterUtil.digest(algorithm, text); }
From source file:org.xcolab.commons.utils.PwdEncryptor.java
License:Open Source License
protected static String encodePassword(String algorithm, String clearTextPassword, byte[] saltBytes) throws PwdEncryptorException { try {/*from w ww. j a va 2 s .c o m*/ if (algorithm.equals(TYPE_BCRYPT)) { String salt = new String(saltBytes); return BCrypt.hashpw(clearTextPassword, salt); } /*else if (algorithm.equals(TYPE_CRYPT) || algorithm.equals(TYPE_UFC_CRYPT)) { return Crypt.crypt( saltBytes, clearTextPassword.getBytes(Digester.ENCODING)); }*/ else if (algorithm.equals(TYPE_SSHA)) { byte[] clearTextPasswordBytes = clearTextPassword.getBytes(Digester.ENCODING); // Create a byte array of salt bytes appended to password bytes byte[] pwdPlusSalt = new byte[clearTextPasswordBytes.length + saltBytes.length]; System.arraycopy(clearTextPasswordBytes, 0, pwdPlusSalt, 0, clearTextPasswordBytes.length); System.arraycopy(saltBytes, 0, pwdPlusSalt, clearTextPasswordBytes.length, saltBytes.length); // Digest byte array MessageDigest sha1Digest = MessageDigest.getInstance("SHA-1"); byte[] pwdPlusSaltHash = sha1Digest.digest(pwdPlusSalt); // Appends salt bytes to the SHA-1 digest. byte[] digestPlusSalt = new byte[pwdPlusSaltHash.length + saltBytes.length]; System.arraycopy(pwdPlusSaltHash, 0, digestPlusSalt, 0, pwdPlusSaltHash.length); System.arraycopy(saltBytes, 0, digestPlusSalt, pwdPlusSaltHash.length, saltBytes.length); // Base64 encode and format string return Base64.encode(digestPlusSalt); } else { return DigesterUtil.digest(algorithm, clearTextPassword); } } catch (NoSuchAlgorithmException nsae) { throw new PwdEncryptorException(nsae.getMessage()); } catch (UnsupportedEncodingException uee) { throw new PwdEncryptorException(uee.getMessage()); } }