Example usage for org.apache.shiro.crypto.hash ConfigurableHashService setHashAlgorithmName

List of usage examples for org.apache.shiro.crypto.hash ConfigurableHashService setHashAlgorithmName

Introduction

In this page you can find the example usage for org.apache.shiro.crypto.hash ConfigurableHashService setHashAlgorithmName.

Prototype

void setHashAlgorithmName(String name);

Source Link

Document

Sets the name of the java.security.MessageDigest MessageDigest algorithm that will be used to compute hashes.

Usage

From source file:org.jasig.cas.adaptors.jdbc.QueryAndEncodeDatabaseAuthenticationHandler.java

License:Apache License

/**
 * Digest encoded password./*from  ww  w  .j  a  v  a2  s .  co  m*/
 *
 * @param encodedPassword the encoded password
 * @param values the values retrieved from database
 * @return the digested password
 */
protected String digestEncodedPassword(final String encodedPassword, final Map<String, Object> values) {
    final ConfigurableHashService hashService = new DefaultHashService();

    if (StringUtils.isNotBlank(this.staticSalt)) {
        hashService.setPrivateSalt(ByteSource.Util.bytes(this.staticSalt));
    }
    hashService.setHashAlgorithmName(this.algorithmName);

    Long numOfIterations = this.numberOfIterations;
    if (values.containsKey(this.numberOfIterationsFieldName)) {
        final String longAsStr = values.get(this.numberOfIterationsFieldName).toString();
        numOfIterations = Long.valueOf(longAsStr);
    }

    hashService.setHashIterations(numOfIterations.intValue());
    if (!values.containsKey(this.saltFieldName)) {
        throw new RuntimeException("Specified field name for salt does not exist in the results");
    }

    final String dynaSalt = values.get(this.saltFieldName).toString();
    final HashRequest request = new HashRequest.Builder().setSalt(dynaSalt).setSource(encodedPassword).build();
    return hashService.computeHash(request).toHex();
}

From source file:to.sauerkraut.krautadmin.KrautAdminModule.java

License:Open Source License

private void bindPasswordService() {
    final KrautAdminConfiguration.SecurityConfiguration securityConfiguration = configuration
            .getSecurityConfiguration();
    final PasswordService passwordService = new PasswordService();
    final ConfigurableHashService hashService = passwordService.getConfigurableHashService();
    hashService.setHashAlgorithmName(securityConfiguration.getPasswordHashFormat());
    hashService.setHashIterations(securityConfiguration.getPasswordHashIterations());
    bind(PasswordService.class).toInstance(passwordService);
}