org.cryptacular.bean.HashBean Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of com.liferay.saml.opensaml.integration Show documentation
Show all versions of com.liferay.saml.opensaml.integration Show documentation
Liferay SAML OpenSAML Integration
/* See LICENSE for licensing and NOTICE for copyright. */
package org.cryptacular.bean;
import org.cryptacular.CryptoException;
import org.cryptacular.StreamException;
/**
* Strategy interface to support beans that produce hash outputs in various formats, e.g. raw bytes, hex output, etc.
*
* @param Type of output (e.g. byte[], string) produced by hash bean.
*
* @author Middleware Services
*/
public interface HashBean
{
/**
* Hashes the given data.
*
* @param data Data to hash. Callers should expect support for at least the following types: byte[]
,
* {@link CharSequence}, {@link java.io.InputStream}, and {@link org.cryptacular.io.Resource}. Unless
* otherwise noted, character data is processed in the UTF-8
character set; if another
* character set is desired, the caller should convert to byte[]
and provide the resulting
* bytes.
*
* @return Digest output.
*
* @throws CryptoException on hash computation errors.
* @throws StreamException on stream IO errors.
*/
T hash(Object... data) throws CryptoException, StreamException;
/**
* Compares a known hash value with the hash of the given data.
*
* @param hash Known hash value.
* @param data Data to hash.
*
* @return True if the hashed data matches the given hash, false otherwise.
*
* @throws CryptoException on hash computation errors.
* @throws StreamException on stream IO errors.
*/
boolean compare(T hash, Object... data) throws CryptoException, StreamException;
}