List of usage examples for org.apache.commons.codec.digest DigestUtils sha256Hex
public static String sha256Hex(String data)
From source file:net.bryansaunders.jee6divelog.util.SecurityUtilsTest.java
/** * Test method for generatePasswordHash. *///from ww w. j a v a2 s . co m @Test public void testGeneratePasswordHash() { // given final String password = "pass123"; // when final String hashedPass = SecurityUtils.generatePasswordHash(password); // then final String expectedPass = Base64.encodeBase64String(DigestUtils.sha256Hex(password).getBytes()); assertEquals(expectedPass, hashedPass); }
From source file:com.ormanli.duplicatefinder.util.FileUtil.java
public String getFileHash(File file) throws Exception { return DigestUtils.sha256Hex(Files.toByteArray(file)); }
From source file:com.github.aynu.yukar.baseline.provider.domain.auth.CertificationTest.java
@Before public void before() throws PersistenceException { testee.save(new Certification("user#01", DigestUtils.sha256Hex("password#01"))); testee.flush();/* ww w. j ava2 s . c o m*/ }
From source file:com.mweagle.tereus.commands.evaluation.common.FileUtils.java
public String fileHash(String pathArg) throws Exception { final Path file = this.templateRoot.resolve(pathArg).normalize(); try (InputStream is = Files.newInputStream(file)) { return DigestUtils.sha256Hex(is); }//from ww w.j a va 2 s.c om }
From source file:com.github.jeromeroucou.javasignedurl.utils.SignedUrlUtils.java
/** * Get SHA256 hash from text passed in parameter. * /*from w ww . j a va2 s .c o m*/ * @param textToBeHashed the text to be hashed * @return the hash from the text passed in parameter's method * @since 1.0 */ public static String hashSha256WithSalt(final String textToBeHashed) { String hash; synchronized (textToBeHashed) { hash = DigestUtils.sha256Hex(textToBeHashed + getSomeSalt()).toUpperCase(); } LOGGER.debug("{} -> SHA256 -> {}", new Object[] { textToBeHashed, hash, }); return hash; }
From source file:com.floragunn.searchguard.authentication.backend.simple.SettingsBasedAuthenticationBackend.java
@Override public User authenticate(final com.floragunn.searchguard.authentication.AuthCredentials authCreds) throws AuthException { final String user = authCreds.getUsername(); final char[] password = authCreds.getPassword(); authCreds.clear();// w w w. j a v a 2 s . c o m String pass = settings.get(ConfigConstants.SEARCHGUARD_AUTHENTICATION_SETTINGSDB_USER + user, null); String digest = settings.get(ConfigConstants.SEARCHGUARD_AUTHENTICATION_SETTINGSDB_DIGEST, null); if (digest != null) { digest = digest.toLowerCase(); switch (digest) { case "sha": case "sha1": pass = DigestUtils.sha1Hex(pass); break; case "sha256": pass = DigestUtils.sha256Hex(pass); break; case "sha384": pass = DigestUtils.sha384Hex(pass); break; case "sha512": pass = DigestUtils.sha512Hex(pass); break; default: pass = DigestUtils.md5Hex(pass); break; } } if (pass != null && Arrays.equals(pass.toCharArray(), password)) { return new User(user); } throw new AuthException("No user " + user + " or wrong password (digest: " + (digest == null ? "plain/none" : digest) + ")"); }
From source file:com.supinfo.supfriends.ejb.controller.editProfileController.java
public String saveChanges() { getLoggedUser().setFirstName(firstname); getLoggedUser().setLastName(lastname); getLoggedUser().setEmail(email);/* w w w. j a v a 2s . c o m*/ getLoggedUser().setLatitude(Double.valueOf(latitude)); getLoggedUser().setLongitude(Double.valueOf(longitude)); String passwordCrypted = DigestUtils.sha256Hex(password); getLoggedUser().setPassword(passwordCrypted); getLoggedUser().setPhoneNumber(phonenumber); getLoggedUser().setUserName(username); boolean isEdited = userFacade.edit(getLoggedUser()); FacesContext context = FacesContext.getCurrentInstance(); if (!isEdited) { FacesMessage message = new FacesMessage( "Un problme est survenu lors de la sauvegarde de votre profil."); context.addMessage(getMybutton().getClientId(context), message); return null; } FacesMessage message = new FacesMessage("Votre profil a t sauvegard."); context.addMessage(getMybutton().getClientId(context), message); return null; }
From source file:com.open.shift.support.controller.SupportResource.java
@POST @Path("auth") @Consumes(MediaType.APPLICATION_FORM_URLENCODED) public void authenticateUser(@FormParam("user") String user, @FormParam("pass") String pass) throws Exception { String hexPass = DigestUtils.sha256Hex(pass); String r = supportDAO.authenticateUser(user, hexPass); if (r.equalsIgnoreCase("fail")) { request.setAttribute("isAuthenticated", false); } else {/*from w w w. j av a 2 s . c om*/ request.setAttribute("isAuthenticated", true); } }
From source file:com.formkiq.core.dao.MigrationDaoImplTest.java
/** * Create Folder Form.// ww w . ja v a 2 s .co m * @param user {@link User} * @param folder {@link UUID} * @param formId {@link UUID} * @return {@link FolderForm} */ private FolderForm createFolderForm(final User user, final UUID folder, final UUID formId) { String sha256hash = DigestUtils.sha256Hex(folder + " " + formId); Asset asset = createAsset("test"); FolderForm form = new FolderForm(); form.setType(ClientFormType.FORM); form.setFolderid(folder); form.setUUID(formId); form.setSha1hash("FFFF"); form.setInsertedDate(new Date()); form.setUpdatedDate(new Date()); form.setAssetid(asset.getAssetId()); form.setData("{}"); form.setStatus(FolderFormStatus.ACTIVE); this.folderDao.saveForm(user, form, sha256hash); return form; }
From source file:it.isislab.dmason.util.SystemManagement.Worker.Digester.java
public String getDigest(String data) { if (digestAlg.equals(DigestAlgorithm.MD2)) digest = DigestUtils.md5Hex(data); if (digestAlg.equals(DigestAlgorithm.MD5)) digest = DigestUtils.md5Hex(data); if (digestAlg.equals(DigestAlgorithm.SHA1)) digest = DigestUtils.sha256Hex(data); return digest; }