AbstractHash

Provides a base for all Shiro Hash algorithms with support for salts and multiple hash iterations. <p/> Read <a href="http://www.owasp.org/index.php/Hashing_Java" target="blank">http://www.owasp.org/index.php/Hashing_Java</a> for a good article on the benefits of hashing, including what a 'salt' is as well as why it and multiple hash iterations can be useful. <p/> This class and its subclasses support hashing with additional capabilities of salting and multiple iterations via overloaded constructors.

deprecated("") in Shiro 1.1 in favor of using the concrete {@link SimpleHash} implementation directly.

abstract
class AbstractHash : CodecSupport , Hash {}

Constructors

this
this()

Creates an new instance without any of its properties set (no hashing is performed). <p/> Because all constructors in this class (except this one) hash the {@code source} constructor argument, this default, no-arg constructor is useful in scenarios when you have a byte array that you know is already hashed and just want to set the bytes in their raw form directly on an instance. After instantiating the instance with this default, no-arg constructor, you can then immediately call {@link #setBytes setBytes} to have a fully-initialized instance.

Inherited Members

From CodecSupport

PREFERRED_ENCODING
enum string PREFERRED_ENCODING;

Shiro's default preferred character encoding, equal to <b><code>UTF-8</code></b>.

toBytes
byte[] toBytes(char[] chars)

Converts the specified character array to a byte array using the Shiro's preferred encoding (UTF-8). <p/> This is a convenience method equivalent to calling the {@link #toBytes(String,String)} method with a a wrapping String and {@link CodecSupport#PREFERRED_ENCODING PREFERRED_ENCODING}, i.e. <p/> <code>toBytes( new String(chars), {@link CodecSupport#PREFERRED_ENCODING PREFERRED_ENCODING} );</code>

isByteSource
bool isByteSource(Object o)

Returns {@code true} if the specified object can be easily converted to bytes by instances of this class, {@code false} otherwise. <p/> The default implementation returns {@code true} IFF the specified object is an instance of one of the following types: <ul> <li>{@code byte[]}</li> <li>{@code char[]}</li> <li>{@link ByteSource}</li> <li>{@link String}</li> <li>{@link File}</li> </li>{@link InputStream}</li> </ul>

toBytes
byte[] toBytes(Object o)

Converts the specified Object into a byte array. <p/> If the argument is a {@code byte[]}, {@code char[]}, {@link ByteSource}, {@link String}, {@link File}, or {@link InputStream}, it will be converted automatically and returned.} <p/> If the argument is anything other than these types, it is passed to the {@link #objectToBytes(Object) objectToBytes} method which must be overridden by subclasses.

From Hash

getAlgorithmName
string getAlgorithmName()

Returns the name of the algorithm used to hash the input source, for example, {@code SHA-256}, {@code MD5}, etc. <p/> The name is expected to be a {@link java.security.MessageDigest MessageDigest} algorithm name.

getSalt
ByteSource getSalt()

Returns a salt used to compute the hash or {@code null} if no salt was used.

getIterations
int getIterations()

Returns the number of hash iterations used to compute the hash.

Meta