1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements.  See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership.  The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License.  You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied.  See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 module hunt.shiro.crypto.hash.Hash;
20 
21 import hunt.shiro.util.ByteSource;
22 
23 /**
24  * A Cryptographic {@code Hash} represents a one-way conversion algorithm that transforms an input source to an
25  * underlying byte array.  Hex and Base64-encoding output of the hashed bytes are automatically supported by the
26  * inherited {@link #toHex() toHex()} and {@link #toBase64() toBase64()} methods.
27  * <p/>
28  * The bytes returned by the parent interface's {@link #getBytes() getBytes()} are the hashed value of the
29  * original input source, also known as the 'checksum' or 'digest'.
30  *
31  * @see Md2Hash
32  * @see Md5Hash
33  * @see Sha1Hash
34  * @see Sha256Hash
35  * @see Sha384Hash
36  * @see Sha512Hash
37  */
38 interface Hash : ByteSource {
39 
40     /**
41      * Returns the name of the algorithm used to hash the input source, for example, {@code SHA-256}, {@code MD5}, etc.
42      * <p/>
43      * The name is expected to be a {@link java.security.MessageDigest MessageDigest} algorithm name.
44      *
45      * @return the the name of the algorithm used to hash the input source, for example, {@code SHA-256}, {@code MD5}, etc.
46      */
47     string getAlgorithmName();
48 
49     /**
50      * Returns a salt used to compute the hash or {@code null} if no salt was used.
51      *
52      * @return a salt used to compute the hash or {@code null} if no salt was used.
53      */
54     ByteSource getSalt();
55 
56     /**
57      * Returns the number of hash iterations used to compute the hash.
58      *
59      * @return the number of hash iterations used to compute the hash.
60      */
61     int getIterations();
62 
63 }