All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.cryptacular.bean.HashBean Maven / Gradle / Ivy

There is a newer version: 6.2.20
Show newest version
/* 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;
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy