List of usage examples for com.google.common.hash Hashing sha512
public static HashFunction sha512()
From source file:org.eclipse.che.security.SHA512PasswordEncryptor.java
@Override public String encrypt(String password) { requireNonNull(password, "Required non-null password"); // generate salt final byte[] salt = new byte[SALT_BYTES_LENGTH]; SECURE_RANDOM.nextBytes(salt);//from ww w .j av a 2 s.c om // sha512(password + salt) final HashCode hash = Hashing.sha512().hashBytes(Bytes.concat(password.getBytes(PWD_CHARSET), salt)); final HashCode saltHash = HashCode.fromBytes(salt); // add salt to the hash, result length (512 / 8) * 2 + (64 / 8) * 2 = 144 return hash.toString() + saltHash.toString(); }
From source file:org.fenixedu.bennu.oauth.domain.ExternalApplication.java
protected void init() { setBennu(Bennu.getInstance());// w w w .ja v a 2 s .c o m setSecret(Base64.getEncoder().encodeToString(Hashing.sha512() .hashBytes(UUID.randomUUID().toString().getBytes(StandardCharsets.UTF_8)).asBytes())); setState(ExternalApplicationState.ACTIVE); }
From source file:security.MyAuthenticationProvider.java
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { UsernamePasswordAuthenticationToken auth = (UsernamePasswordAuthenticationToken) authentication; String username = String.valueOf(auth.getPrincipal()); String password = String.valueOf(auth.getCredentials()); // 1. Use the username to load the data for the user, including authorities and password. User user = (User) userRepository.findOneByUsername(username); if (user == null) throw new BadCredentialsException("Bad Credentials"); String saltPassword = Hashing.sha512().hashString(password + user.getSalt(), Charsets.UTF_8).toString(); System.out.println("Salted pass: " + saltPassword); // 2. Check the passwords match. if (!user.getPassword().equals(saltPassword)) { throw new BadCredentialsException("Bad Credentials"); }/* w w w . j ava2 s . c o m*/ // 3. Preferably clear the password in the user object before storing in authentication object //user.clearPassword(); // 4. Return an authenticated token, containing user data and authorities List<GrantedAuthority> authorities = new ArrayList<>(); authorities.add(new SimpleGrantedAuthority("ROLE_USER")); Authentication token = new UsernamePasswordAuthenticationToken(user, saltPassword, authorities); return token; }
From source file:com.infinities.keystone4j.utils.PasswordUtils.java
public static String hashPassword(String password) { if (Strings.isNullOrEmpty(password)) { throw new IllegalArgumentException(); }//from w w w . j a va2 s .c o m String passwordUtf8 = verifyLengthAndtruncPassword(password); // hash round? and identify String hashed = Hashing.sha512().hashString(passwordUtf8, Charsets.UTF_8).toString(); return hashed; }
From source file:org.apache.james.user.jpa.model.JPAUser.java
@SuppressWarnings("deprecation") private static HashFunction chooseHashing(String algorithm) { switch (algorithm) { case "MD5": return Hashing.md5(); case "SHA-256": return Hashing.sha256(); case "SHA-512": return Hashing.sha512(); default:/*w w w. java2s . c o m*/ return Hashing.sha1(); } }
From source file:org.eclipse.che.security.SHA512PasswordEncryptor.java
@Override public boolean test(String password, String passwordHash) { requireNonNull(password, "Required non-null password"); requireNonNull(passwordHash, "Required non-null password's hash"); // retrieve salt from the hash final int passwordHashLength = ENCRYPTED_PASSWORD_BYTES_LENGTH * 2; if (passwordHash.length() < passwordHashLength + SALT_BYTES_LENGTH * 2) { return false; }// w w w . j a v a2 s. com final HashCode saltHash = HashCode.fromString(passwordHash.substring(passwordHashLength)); // sha1(password + salt) final HashCode hash = Hashing.sha512() .hashBytes(Bytes.concat(password.getBytes(PWD_CHARSET), saltHash.asBytes())); // test sha1(password + salt) + salt == passwordHash return (hash.toString() + saltHash.toString()).equals(passwordHash); }
From source file:ph.samson.maven.enforcer.rule.checksum.FileChecksum.java
@Override public void execute(EnforcerRuleHelper erh) throws EnforcerRuleException { if (file == null || !file.canRead()) { throw new EnforcerRuleException("Missing file: " + file); }//from ww w .ja va 2 s . co m HashFunction hashFn; switch (type) { case "crc32": hashFn = Hashing.crc32(); break; case "crc32c": hashFn = Hashing.crc32c(); break; case "md5": hashFn = Hashing.md5(); break; case "sha1": hashFn = Hashing.sha1(); break; case "sha256": hashFn = Hashing.sha256(); break; case "sha512": hashFn = Hashing.sha512(); break; default: throw new EnforcerRuleException("Unsupported hash type: " + type); } String hash; try { hash = hashFn.hashBytes(Files.readAllBytes(file.toPath())).toString(); } catch (IOException ex) { throw new EnforcerRuleException("Failed reading " + file, ex); } if (!hash.equalsIgnoreCase(checksum)) { throw new EnforcerRuleException( type + " hash of " + file + " was " + hash + " but expected " + checksum); } }
From source file:sockslib.server.manager.HashPasswordProtector.java
private Hasher chooseHasher(HashAlgorithm algorithm) { Hasher hasher = null;/* w w w. j a v a2s. com*/ switch (algorithm) { case MD5: hasher = Hashing.md5().newHasher(); break; case SHA1: hasher = Hashing.sha1().newHasher(); break; case SHA256: hasher = Hashing.sha256().newHasher(); break; case SHA512: hasher = Hashing.sha512().newHasher(); break; } return hasher; }
From source file:org.fenixedu.academic.domain.candidacy.GenericApplication.java
private String generateConfirmationLink() { final String confirmationCode = Hashing.sha512().hashString(getEmail() + System.currentTimeMillis() + hashCode() + new Random(System.currentTimeMillis()).nextGaussian(), Charsets.UTF_8).toString(); setConfirmationCode(confirmationCode); return FenixEduAcademicConfiguration.getConfiguration().getGenericApplicationEmailConfirmationLink() + confirmationCode + "&applicationExternalId=" + getExternalId(); }
From source file:net.sourceforge.fenixedu.domain.candidacy.GenericApplication.java
private String generateConfirmationLink() { final String confirmationCode = Hashing.sha512().hashString(getEmail() + System.currentTimeMillis() + hashCode() + new Random(System.currentTimeMillis()).nextGaussian(), Charsets.UTF_8).toString(); setConfirmationCode(confirmationCode); return FenixConfigurationManager.getConfiguration().getGenericApplicationEmailConfirmationLink() + confirmationCode + "&applicationExternalId=" + getExternalId(); }