List of usage examples for org.apache.commons.codec.digest DigestUtils sha512Hex
public static String sha512Hex(String data)
From source file:de.hub.cses.ces.jsf.bean.game.SetupBean.java
/** * *//* w w w. ja v a2s .c om*/ public void unlock() { if (this.password == null) { return; } String secret = DigestUtils.sha512Hex(password); if (secret.equals(game.getPassword())) { this.unlocked = true; } }
From source file:com.sunrun.crportal.util.CRPortalUtil.java
/** * Common method to generate an SHA-512 cipher * @param subject/*from w w w. j a v a2s .com*/ * @return * @throws CRPortletException */ private static String _cipherCreate(String subject) throws CRPortletException { String cipherString = null; cipherString = DigestUtils.sha512Hex(subject); return cipherString; }
From source file:com.krminc.phr.domain.User.java
public void setPassword(String password) { this.password = DigestUtils.sha512Hex(password); }
From source file:com.krminc.phr.domain.User.java
public Boolean testPassword(String testPassword) { return (this.password.equals(DigestUtils.sha512Hex(testPassword))); }
From source file:com.nebkat.plugin.text.TextPlugin.java
@EventHandler @CommandFilter("hash") public void onHashCommand(CommandEvent e) { if (e.getParams().length < 2) { e.showUsage(getBot());//from www.j a v a 2 s . c o m return; } String algorithm = e.getParams()[0]; String text = e.getRawParams().substring(algorithm.length() + 1); String result = "Algorithm unsupported"; if (algorithm.equalsIgnoreCase("md5")) { result = DigestUtils.md5Hex(text); } else if (algorithm.equalsIgnoreCase("md2")) { result = DigestUtils.md2Hex(text); } else if (algorithm.equalsIgnoreCase("sha1") || algorithm.equalsIgnoreCase("sha")) { result = DigestUtils.sha1Hex(text); } else if (algorithm.equalsIgnoreCase("sha256")) { result = DigestUtils.sha256Hex(text); } else if (algorithm.equalsIgnoreCase("sha384")) { result = DigestUtils.sha384Hex(text); } else if (algorithm.equalsIgnoreCase("sha512")) { result = DigestUtils.sha512Hex(text); } Irc.message(e.getSession(), e.getTarget(), e.getSource().getNick() + ": " + result); }
From source file:edu.kit.dama.staging.processor.impl.InputHashOP.java
/** * Hash a single file using the internally defined hash algorithm. * * @param pFile The file to hash/* w ww. j av a 2 s . co m*/ * * @return The hash value * * @throws IOException If pFile cannot be read */ private String hashFile(File pFile) throws IOException { LOGGER.debug("Hashing file {}", pFile.getAbsolutePath()); InputStream is = null; try { is = new FileInputStream(pFile); String hash; switch (hashType) { case SHA: hash = DigestUtils.sha1Hex(is); break; case SHA256: hash = DigestUtils.sha256Hex(is); break; case SHA384: hash = DigestUtils.sha384Hex(is); break; case SHA512: hash = DigestUtils.sha512Hex(is); break; default: hash = DigestUtils.md5Hex(is); } return hash; } finally { if (is != null) { try { is.close(); } catch (IOException ioe) { //ignore } } } }
From source file:de.elomagic.maven.http.HTTPMojo.java
private void checkFile(final Path path) throws Exception { String fileDigest;/* ww w.j ava2 s. c o m*/ try (InputStream in = Files.newInputStream(path)) { switch (digestType.toLowerCase()) { case "md5": fileDigest = DigestUtils.md5Hex(in); break; case "sha1": fileDigest = DigestUtils.sha1Hex(in); break; case "sha256": fileDigest = DigestUtils.sha256Hex(in); break; case "sha384": fileDigest = DigestUtils.sha384Hex(in); break; case "sha512": fileDigest = DigestUtils.sha512Hex(in); break; default: throw new Exception("Digest type \"" + digestType + "\" not supported."); } } if (!fileDigest.equalsIgnoreCase(digest)) { throw new Exception( digestType + " digest check failed. File=\"" + fileDigest + "\", Digest=\"" + digest + "\""); } }
From source file:com.krminc.phr.security.PHRRealm.java
/** * Checks the authentication of a user and returns the groups it belongs to. * * @return groups that this particular user belongs to *//*from w w w. j av a2 s . co m*/ public String[] authenticateUser(String user, String password) { String query = "SELECT password, requires_reset, is_locked_out, active, failed_password_attempts FROM user_users WHERE username = ?"; ResultSet rs = null; String passwordHash = new String(); boolean requiresReset = false; boolean lockedOut = false; boolean active = false; int failedAttemptsVal = 0; PreparedStatement st = null; try { createDS(); conn = ds.getNonTxConnection(); st = conn.prepareStatement(query); st.setString(1, user); rs = st.executeQuery(); } catch (Exception e) { log("Error getting password from database"); log(e.getMessage()); rs = null; } finally { try { conn.close(); } catch (Exception e) { log(e.getMessage()); } conn = null; } if (rs != null) { try { if (rs.next()) { passwordHash = rs.getString(1); requiresReset = rs.getBoolean(2); lockedOut = rs.getBoolean(3); active = rs.getBoolean(4); failedAttemptsVal = rs.getInt(5); } } catch (Exception e) { log("Error getting password from resultset"); log(e.getMessage()); } finally { try { st.close(); rs.close(); } catch (Exception e) { log(e.getMessage()); } } } //inactive users have no roles, no login attempt monitoring if (!active) return null; //locked users have a locked role, which is filtered by the Login class as needed if (lockedOut) { incrementFailedUpdate(user); String[] lock = { lockedRole }; return lock; } if (!passwordHash.isEmpty()) { if (passwordHash.equals(DigestUtils.sha512Hex(password))) { //password is correct //find and return groups String[] retArr = null; try { Enumeration userGroups = getGroupNames(user); ArrayList retGroups = new ArrayList(); //populate with groups from db while (userGroups.hasMoreElements()) { retGroups.add(userGroups.nextElement().toString()); } //force password reset if needed by adding role if (requiresReset) { retGroups.add(resetRole); } //formulate returnable collection Object[] arr = retGroups.toArray(); retArr = new String[arr.length]; for (int i = 0; i < arr.length; i++) { retArr[i] = arr[i].toString(); } } catch (NoSuchUserException e) { log("Exception encountered looking up password"); } catch (Exception e) { log("Group lookup error: " + e.getClass() + ":" + e.getMessage()); } //reset bad login info, if needed, now that we're successful // this will only happen for valid logins and pw reset logins, not locks or inactive accts if (failedAttemptsVal > 0) doSuccessfulUpdate(user); return retArr; } else { log("Passwords do not match"); try { InvalidPasswordAttempt(user); } catch (NoSuchUserException e) { //not an issue here } } } else { log("Unable to find user password"); } return null; }
From source file:com.remediatetheflag.global.persistence.HibernatePersistenceFacade.java
public Boolean updateUserPassword(Integer idUser, String newPwd) { String salt = RandomGenerator.getNextSalt(); String pwd = DigestUtils.sha512Hex(newPwd.concat(salt)); User user = getUserFromUserId(idUser); user.setSalt(salt);/*from ww w. j a v a 2 s . c om*/ user.setPassword(pwd); HibernateSessionTransactionWrapper hb = openSessionTransaction(); try { hb.localSession.update(user); closeSessionTransaction(hb); return true; } catch (Exception e) { closeSessionTransaction(hb); logger.error(e.getMessage()); return false; } }
From source file:de.betterform.agent.web.WebProcessor.java
private String generateXFormsSessionKey() { StringBuffer key = new StringBuffer(String.valueOf(System.currentTimeMillis())); key.append(String.valueOf(Math.random())); return DigestUtils.sha512Hex(key.toString()); }