Example usage for org.apache.shiro.crypto.hash.format HashFormat format

List of usage examples for org.apache.shiro.crypto.hash.format HashFormat format

Introduction

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

Prototype

String format(Hash hash);

Source Link

Document

Returns a formatted string representing the specified Hash instance.

Usage

From source file:com.meltmedia.cadmium.cli.AuthCommand.java

License:Apache License

/**
 * Hashes a password the shiro way./*from w w w . j av  a2 s . c o m*/
 * @return
 */
private String hashPasswordForShiro() {
    //Hash password
    HashFormatFactory HASH_FORMAT_FACTORY = new DefaultHashFormatFactory();
    SecureRandomNumberGenerator generator = new SecureRandomNumberGenerator();
    int byteSize = 128 / 8;
    ByteSource salt = generator.nextBytes(byteSize);

    SimpleHash hash = new SimpleHash("SHA-256", password, salt, 10);

    HashFormat format = HASH_FORMAT_FACTORY.getInstance("shiro1");
    return format.format(hash);
}

From source file:org.obiba.shiro.tools.hasher.Hasher.java

License:Open Source License

public static String hash(String value) {
    Hash hash = new SimpleHash(DEFAULT_PASSWORD_ALGORITHM_NAME, value, getSalt(),
            DEFAULT_PASSWORD_NUM_ITERATIONS);
    HashFormat format = HASH_FORMAT_FACTORY.getInstance(Shiro1CryptFormat.class.getName());
    return format.format(hash);
}