Example usage for org.apache.shiro.authc.credential DefaultPasswordService setHashService

List of usage examples for org.apache.shiro.authc.credential DefaultPasswordService setHashService

Introduction

In this page you can find the example usage for org.apache.shiro.authc.credential DefaultPasswordService setHashService.

Prototype

public void setHashService(HashService hashService) 

Source Link

Usage

From source file:com.mycompany.shirofaces.SHA256.java

public static void main(String args[]) {
    RandomNumberGenerator rng = new SecureRandomNumberGenerator();
    Object salt = rng.nextBytes();
    String hashedPasswordBase64 = new Sha256Hash("juancho18", salt, 1024).toBase64();

    Sha256Hash sha256Hash = new Sha256Hash("juancho18");
    System.out.println("Clave sin salt: " + sha256Hash.toHex());
    System.out.println("Clave con salt : " + hashedPasswordBase64);

    DefaultHashService hashService = new DefaultHashService();
    hashService.setHashIterations(50000); // 500000
    hashService.setHashAlgorithmName(Sha256Hash.ALGORITHM_NAME);
    hashService.setPrivateSalt(new SimpleByteSource("jumarome"));
    hashService.setGeneratePublicSalt(true);

    DefaultPasswordService passwordService = new DefaultPasswordService();
    passwordService.setHashService(hashService);
    String salte = hashService.getPrivateSalt().toBase64();
    String claveMaldita = passwordService.encryptPassword("unaep");
    System.out.println("Miraaa: " + claveMaldita);

    System.out.println("private salt= " + salte);

}

From source file:edu.eci.pdsw.aeci.seguridad.ShiroLoginBean.java

/**
 * //from   ww w.j  a v  a2 s  . c  om
 * @param password The password to encrypt
 * @return the password encrypted
 */
public static String generateHash(String password) {
    DefaultHashService hashService = new DefaultHashService();
    hashService.setHashIterations(500000);
    hashService.setHashAlgorithmName(Sha256Hash.ALGORITHM_NAME);

    hashService.setPrivateSalt(new SimpleByteSource("myprivatesalt"));
    hashService.setGeneratePublicSalt(true);

    DefaultPasswordService passwordService = new DefaultPasswordService();
    passwordService.setHashService(hashService);
    String encryptedPassword = passwordService.encryptPassword(password);

    return encryptedPassword;
}

From source file:edu.eci.pdsw.samples.managedbeans.LogginBean.java

public static String generateHash(String password) {
    DefaultHashService hashService = new DefaultHashService();
    hashService.setHashIterations(500000); // 500000
    hashService.setHashAlgorithmName(Sha256Hash.ALGORITHM_NAME);

    // Same salt as in shiro.ini, but NOT base64-encoded!!
    hashService.setPrivateSalt(new SimpleByteSource("myprivatesalt"));
    hashService.setGeneratePublicSalt(true);

    DefaultPasswordService passwordService = new DefaultPasswordService();
    passwordService.setHashService(hashService);
    String encryptedPassword = passwordService.encryptPassword(password);
    return encryptedPassword;

}

From source file:edu.eci.pdsw.samples.persistence.mybatisimpl.MyBatisDAOSolicitud.java

License:Open Source License

public static String generateHash(String password) {
    DefaultHashService hashService = new DefaultHashService();
    hashService.setHashIterations(500000); // 500000
    hashService.setHashAlgorithmName(Sha256Hash.ALGORITHM_NAME);

    // Same salt as in shiro.ini, but NOT base64-encoded!!
    hashService.setPrivateSalt(new SimpleByteSource("myprivatesalt"));
    hashService.setGeneratePublicSalt(true);

    DefaultPasswordService passwordService = new DefaultPasswordService();
    passwordService.setHashService(hashService);
    String encryptedPassword = passwordService.encryptPassword(password);

    return encryptedPassword;

}

From source file:org.hawk.service.server.users.servlet.db.UserStorage.java

License:Open Source License

public static HashingPasswordService getPasswordService() {
    DefaultHashService hashService = new DefaultHashService();
    hashService.setHashIterations(HASH_ITERATIONS);
    hashService.setHashAlgorithmName(Sha512Hash.ALGORITHM_NAME);
    hashService.setGeneratePublicSalt(true);

    DefaultPasswordService passwordService = new DefaultPasswordService();
    passwordService.setHashService(hashService);
    return passwordService;
}