Example usage for org.apache.shiro.crypto.hash.format HashFormatFactory getInstance

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

Introduction

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

Prototype

HashFormat getInstance(String token);

Source Link

Usage

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

License:Apache License

/**
 * Hashes a password the shiro way.//w  w  w .ja  v a2s .  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);
}