001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.shiro.crypto.hash;
020
021import org.apache.shiro.util.ByteSource;
022
023/**
024 * A Cryptographic {@code Hash} represents a one-way conversion algorithm that transforms an input source to an
025 * underlying byte array.  Hex and Base64-encoding output of the hashed bytes are automatically supported by the
026 * inherited {@link #toHex() toHex()} and {@link #toBase64() toBase64()} methods.
027 * <p/>
028 * The bytes returned by the parent interface's {@link #getBytes() getBytes()} are the hashed value of the
029 * original input source, also known as the 'checksum' or 'digest'.
030 *
031 * @see Md2Hash
032 * @see Md5Hash
033 * @see Sha1Hash
034 * @see Sha256Hash
035 * @see Sha384Hash
036 * @see Sha512Hash
037 * @since 0.9
038 */
039public interface Hash extends ByteSource {
040
041    /**
042     * Returns the name of the algorithm used to hash the input source, for example, {@code SHA-256}, {@code MD5}, etc.
043     * <p/>
044     * The name is expected to be a {@link java.security.MessageDigest MessageDigest} algorithm name.
045     *
046     * @return the the name of the algorithm used to hash the input source, for example, {@code SHA-256}, {@code MD5}, etc.
047     * @since 1.1
048     */
049    String getAlgorithmName();
050
051    /**
052     * Returns a salt used to compute the hash or {@code null} if no salt was used.
053     *
054     * @return a salt used to compute the hash or {@code null} if no salt was used.
055     * @since 1.2
056     */
057    ByteSource getSalt();
058
059    /**
060     * Returns the number of hash iterations used to compute the hash.
061     *
062     * @return the number of hash iterations used to compute the hash.
063     * @since 1.2
064     */
065    int getIterations();
066
067}