Java Code Examples for org.apache.shiro.crypto.hash.HashRequest#Builder
The following examples show how to use
org.apache.shiro.crypto.hash.HashRequest#Builder .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SHA512.java From JavaSecurity with Apache License 2.0 | 6 votes |
private static Hash calculateHash(String password) { ByteSource privateSalt = ByteSource.Util.bytes(PRIVATE_SALT_BYTES); DefaultHashService hashService = new DefaultHashService(); hashService.setPrivateSalt(privateSalt); hashService.setGeneratePublicSalt(true); hashService.setHashIterations(ITERATIONS); HashRequest.Builder builder = new HashRequest.Builder(); builder.setSource(ByteSource.Util.bytes(password)); Hash hash = hashService.computeHash(builder.build()); log.info("Hash algorithm {}, iterations {}, public salt {}", hash.getAlgorithmName(), hash.getIterations(), hash.getSalt()); return hash; }
Example 2
Source File: SHA512.java From JavaSecurity with Apache License 2.0 | 6 votes |
private static boolean verifyPassword(byte[] originalHash, ByteSource publicSalt, String password) { ByteSource privateSalt = ByteSource.Util.bytes(PRIVATE_SALT_BYTES); DefaultHashService hashService = new DefaultHashService(); hashService.setPrivateSalt(privateSalt); hashService.setHashIterations(ITERATIONS); HashRequest.Builder builder = new HashRequest.Builder(); builder.setSource(ByteSource.Util.bytes(password)); builder.setSalt(publicSalt); Hash comparisonHash = hashService.computeHash(builder.build()); log.info("password: {}", password); log.info("1 hash: {}", Hex.encodeToString(originalHash)); log.info("2 hash: {}", comparisonHash.toHex()); return Arrays.equals(originalHash, comparisonHash.getBytes()); }
Example 3
Source File: LdapRealm.java From zeppelin with Apache License 2.0 | 5 votes |
@Override protected AuthenticationInfo createAuthenticationInfo(AuthenticationToken token, Object ldapPrincipal, Object ldapCredentials, LdapContext ldapContext) throws NamingException { HashRequest.Builder builder = new HashRequest.Builder(); Hash credentialsHash = hashService .computeHash(builder.setSource(token.getCredentials()) .setAlgorithmName(HASHING_ALGORITHM).build()); return new SimpleAuthenticationInfo(token.getPrincipal(), credentialsHash.toHex(), credentialsHash.getSalt(), getName()); }
Example 4
Source File: KnoxLdapRealm.java From knox with Apache License 2.0 | 4 votes |
@Override protected AuthenticationInfo createAuthenticationInfo(AuthenticationToken token, Object ldapPrincipal, Object ldapCredentials, LdapContext ldapContext) throws NamingException { HashRequest.Builder builder = new HashRequest.Builder(); Hash credentialsHash = hashService.computeHash(builder.setSource(token.getCredentials()).setAlgorithmName(HASHING_ALGORITHM).build()); return new SimpleAuthenticationInfo(token.getPrincipal(), credentialsHash.toHex(), credentialsHash.getSalt(), getName()); }