#439
[Java] Hash a string/password (with or without salt)
Method :
private static final String HASH_METHOD = "SHA-256"; private String hash(final String password) throws CryptEUException { try { MessageDigest md = MessageDigest.getInstance(HASH_METHOD); md.update(password.getBytes()); byte byteData[] = md.digest(); // convert the byte to hex format StringBuffer sb = new StringBuffer(); for (int i = 0; i < byteData.length; i++) { sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1)); } return sb.toString(); } catch (NoSuchAlgorithmException e) { LOGGER.debug("NoSuchAlgorithmException", e); } }
Call for password only :
hash(password)
Call for password + salt :
hash(password + salt)
Call for password + random salt :
hash(password + RandomStringUtils.randomAlphanumeric(10))
[Java] Read MANIFEST.MF information [Velocity] Allow reload of templates without weblogic restart (dev only)
Comments are currently closed.