List of usage examples for org.apache.commons.codec.digest DigestUtils sha1Hex
public static String sha1Hex(String data)
From source file:com.nextdoor.bender.handler.s3.S3InternalEvent.java
@Override public LinkedHashMap<String, String> getPartitions() { LinkedHashMap<String, String> partitions = super.getPartitions(); if (partitions == null) { partitions = new LinkedHashMap<String, String>(1); super.setPartitions(partitions); }/*from ww w.jav a 2 s . co m*/ partitions.put(FILENAME_PARTITION, DigestUtils.sha1Hex(this.s3Key)); return partitions; }
From source file:com.searchcode.app.util.AESEncryptor.java
private void setKey(String key) { this.key = DigestUtils.sha1Hex(key).substring(0, 16).getBytes(StandardCharsets.UTF_8); }
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();/*from www .jav a 2 s. c om*/ 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:br.com.bob.dashboard.service.UserService.java
public User getUser(final String login, final String password) { final String encoded = DigestUtils.sha1Hex(password); final User get = userDAO.findByLoginEqualAndPasswordEqual(login, encoded); if (get != null) return get; else//from w w w .j a va 2s . c o m throw new BusinessException("Usurio no encontrado"); }
From source file:de.elomagic.carafile.client.CaraFileUtils.java
/** * Creates a meta file from the given file. * * @param path Path of the file/*from www . java 2 s . com*/ * @param filename Real name of the file because it can differ from path parameter * @return * @throws IOException * @throws GeneralSecurityException */ public static final MetaData createMetaData(final Path path, final String filename) throws IOException, GeneralSecurityException { if (Files.notExists(path)) { throw new FileNotFoundException("File " + path.toString() + " not found!"); } if (Files.isDirectory(path)) { throw new IllegalArgumentException("Not a file: " + path.toString()); } MetaData md = new MetaData(); md.setSize(Files.size(path)); md.setFilename(filename); md.setCreationDate(new Date()); md.setChunkSize(DEFAULT_PIECE_SIZE); try (InputStream in = Files.newInputStream(path, StandardOpenOption.READ); BufferedInputStream bin = new BufferedInputStream(in)) { MessageDigest mdComplete = MessageDigest.getInstance(MessageDigestAlgorithms.SHA_1); byte[] buffer = new byte[DEFAULT_PIECE_SIZE]; int bytesRead; while ((bytesRead = bin.read(buffer)) > 0) { mdComplete.update(buffer, 0, bytesRead); ChunkData chunk = new ChunkData( DigestUtils.sha1Hex(new ByteArrayInputStream(buffer, 0, bytesRead))); md.addChunk(chunk); } String sha1 = Hex.encodeHexString(mdComplete.digest()); md.setId(sha1); } return md; }
From source file:com.machinepublishers.jbrowserdriver.HttpCache.java
/** * {@inheritDoc}// w w w .j a v a 2s. c o m */ @Override public void removeEntry(String key) throws IOException { try (Lock lock = new Lock(new File(cacheDir, DigestUtils.sha1Hex(key)), false, false)) { lock.file.delete(); } catch (FileNotFoundException e) { //ignore } }
From source file:com.searchcode.app.dto.CodeIndexDocument.java
/** * Used for identification for this specific file in the index */// w w w .java 2 s . c o m public String getHash() { return DigestUtils.sha1Hex(this.repoLocationRepoNameLocationFilename); }
From source file:com.biglakesystems.biglib.quality.Exceptions.java
/** * Generate a unique identifier for an exception. Combines the exception class name, identity hash code, and an * ever-incrementing sequence value into a string and then performs a SHA-1 hash of that string, returning the hex * hash./*from w w w . ja v a 2s . co m*/ * * @param exception the exception. * @return {@link String} unique identifier. */ private static String newUniqueId(final Throwable exception) { final String content = String.format("%s_%08x_%08x", exception.getClass().getName(), System.identityHashCode(exception), s_nextIdSequence.getAndIncrement()); return DigestUtils.sha1Hex(content); }
From source file:com.petalmd.armor.authentication.backend.simple.SettingsBasedAuthenticationBackend.java
@Override public User authenticate(final com.petalmd.armor.authentication.AuthCredentials authCreds) throws AuthException { final String user = authCreds.getUsername(); final String clearTextPassword = authCreds.getPassword() == null ? null : new String(authCreds.getPassword()); authCreds.clear();/* w w w . java 2 s. c o m*/ String digest = settings.get(ConfigConstants.ARMOR_AUTHENTICATION_SETTINGSDB_DIGEST, null); final String storedPasswordOrDigest = settings .get(ConfigConstants.ARMOR_AUTHENTICATION_SETTINGSDB_USER + user, null); if (!StringUtils.isEmpty(clearTextPassword) && !StringUtils.isEmpty(storedPasswordOrDigest)) { String passwordOrHash = clearTextPassword; if (digest != null) { digest = digest.toLowerCase(); switch (digest) { case "sha": case "sha1": passwordOrHash = DigestUtils.sha1Hex(clearTextPassword); break; case "sha256": passwordOrHash = DigestUtils.sha256Hex(clearTextPassword); break; case "sha384": passwordOrHash = DigestUtils.sha384Hex(clearTextPassword); break; case "sha512": passwordOrHash = DigestUtils.sha512Hex(clearTextPassword); break; default: passwordOrHash = DigestUtils.md5Hex(clearTextPassword); break; } } if (storedPasswordOrDigest.equals(passwordOrHash)) { return new User(user); } } throw new AuthException("No user " + user + " or wrong password (digest: " + (digest == null ? "plain/none" : digest) + ")"); }
From source file:edu.jhuapl.openessence.security.OEPasswordEncoder.java
/** * * @param rawPass// www.jav a 2 s . 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; }