List of usage examples for org.apache.commons.codec.digest DigestUtils sha256Hex
public static String sha256Hex(String data)
From source file:edu.jhuapl.openessence.security.OEPasswordEncoder.java
/** * * @param rawPass/* w w w.j a v a 2s.c o m*/ * @param encryptDetails an {@link EncryptionDetails} object * @return The encrypted version of the password * @throws DataAccessException */ @Override public String encodePassword(String rawPass, Object encryptDetails) throws DataAccessException { if ((encryptDetails == null) || !(encryptDetails.getClass().equals(EncryptionDetails.class))) { return ""; } String encPass = ""; String salt = ((EncryptionDetails) encryptDetails).getSalt(); String algorithm = ((EncryptionDetails) encryptDetails).getAlgorithm(); if (algorithm.equals("SHA-1")) { log.warn("SHA-1 DEPRECATED, retained for compatibility."); encPass = DigestUtils.sha1Hex(salt + rawPass); } else if (algorithm.equals("SHA-256")) { log.warn("SHA-256 DEPRECATED, retained for compatibility."); encPass = DigestUtils.sha256Hex(salt + rawPass); } else if (algorithm.equals("SHA-384")) { log.warn("SHA-384 DEPRECATED, retained for compatibility."); encPass = DigestUtils.sha384Hex(salt + rawPass); } else if (algorithm.equals("SHA-512")) { log.warn("SHA-512 DEPRECATED, retained for compatibility."); encPass = DigestUtils.sha512Hex(salt + rawPass); } else if (algorithm.equals("BCrypt")) { encPass = BCrypt.hashpw(rawPass, salt); } return encPass; }
From source file:com.payu.sdk.utils.SignUtil.java
/** * Generates the signature based on information received. * * @param algorithm The algorithm used to generate the sign. * @param key The message key.// w w w . j av a 2 s.com * @param message The message to create the signature. * @return the signature created. */ public static String createSignature(final String algorithm, final String key, final String message) { final String str = key + SIGNATURE_SEPARATOR + message; String signature = null; final String localAlgorithm = StringUtils.isBlank(algorithm) ? DEFAULT_ALGORITHM : algorithm; if (Constants.ALGORITHM_MD5.equalsIgnoreCase(localAlgorithm)) { signature = DigestUtils.md5Hex(str); } else if (Constants.ALGORITHM_SHA.equalsIgnoreCase(localAlgorithm)) { signature = DigestUtils.shaHex(str); } else if (Constants.ALGORITHM_SHA_256.equalsIgnoreCase(localAlgorithm)) { signature = DigestUtils.sha256Hex(str); } else { throw new IllegalArgumentException("Could not create signature. Invalid algorithm " + localAlgorithm); } return signature; }
From source file:com.streamsets.lib.security.http.DisconnectedSecurityInfo.java
public Entry getEntry(String userName) { return entries.get(DigestUtils.sha256Hex(userName)); }
From source file:com.arrow.acs.GatewayPayloadSigner.java
private static String hash(String value) { return DigestUtils.sha256Hex(value); }
From source file:com.open.shift.support.controller.SupportResource.java
@POST @Produces(MediaType.TEXT_PLAIN)/*from w w w . j a va 2 s .c o m*/ public String addUsers(@FormParam("user") String user, @FormParam("pass") String pass) { try { String hexPass = DigestUtils.sha256Hex(pass); supportDAO.addUsers(user, hexPass); return "Done"; } catch (Exception ex) { ex.printStackTrace(); System.out.println("Inside supp ex"); return "Fail"; } }
From source file:ApplicationDao.CustomerDao.java
public Customer getCustomerByEmailandPassword(String email, String password) { em.getTransaction().begin();/*from w ww. j av a2 s . c o m*/ Customer cusObj = null; Query q = em.createNamedQuery("findCustomerByEmailandPassword").setParameter("email", email) .setParameter("password", (DigestUtils.sha256Hex(password))); try { cusObj = (Customer) q.getSingleResult(); } catch (NoResultException nre) { return null; } em.getTransaction().commit(); return cusObj; }
From source file:net.bryansaunders.jee6divelog.dao.user.UserAccountDaoIT.java
/** * Test method for save().//w w w . j a va2 s . c o m */ @Test @UsingDataSet("Empty.yml") @ShouldMatchDataSet("expected/GenericDaoIT-ifNotNullThenSave.yml") public void ifNotNullThenSave() { // given final String pass = "abcdef1A@"; final UserAccount validUser = new UserAccount(); validUser.setFirstName("Bryan"); validUser.setLastName("Saunders"); validUser.setEmail("bryan@test.com"); validUser.setCity("Charleston"); validUser.setState("SC"); validUser.setCountry("USA"); validUser.setPassword(pass); // when final UserAccount savedUser = this.userDao.save(validUser); // check the password final String hashedEncodedPass = Base64.encodeBase64String(DigestUtils.sha256Hex(pass).getBytes()); assertEquals(hashedEncodedPass, savedUser.getPassword()); }
From source file:io.hawkcd.services.UserService.java
@Override @Authorization(scope = PermissionScope.SERVER, type = PermissionType.ADMIN) public ServiceResult add(User user) { ServiceResult result = this.getByEmail(user.getEmail()); if (result.getNotificationType() == NotificationType.ERROR) { return result; }//from ww w . j a v a 2s . c o m String password = user.getPassword(); String hashedPassword = DigestUtils.sha256Hex(password); user.setPassword(hashedPassword); return super.add(user); }
From source file:com.cangqu.gallery.server.base.utils.EncodeUtils.java
/** * SHA256? * @param str ? * @return SHA256 */ public static String sha(String str) { return DigestUtils.sha256Hex(str); }
From source file:com.streamsets.lib.security.http.DisconnectedSecurityInfo.java
public void addEntry(String userName, String passwordHash, List<String> roles, List<String> groups) { Entry entry = new Entry(); entry.setUserNameSha(DigestUtils.sha256Hex(userName)); entry.setPasswordHash(passwordHash); entry.getRoles().addAll(roles);//from ww w . j a v a2s . co m entry.getGroups().addAll(groups); entries.put(entry.getUserNameSha(), entry); }