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.codec.Base64;
022import org.apache.shiro.codec.Hex;
023
024
025/**
026 * Generates an SHA-1 Hash (Secure Hash Standard, NIST FIPS 180-1) from a given input <tt>source</tt> with an
027 * optional <tt>salt</tt> and hash iterations.
028 * <p/>
029 * See the {@link SimpleHash SimpleHash} parent class JavaDoc for a detailed explanation of Hashing
030 * techniques and how the overloaded constructors function.
031 *
032 * @since 0.9
033 */
034public class Sha1Hash extends SimpleHash {
035
036    //TODO - complete JavaDoc
037
038    public static final String ALGORITHM_NAME = "SHA-1";
039
040    public Sha1Hash() {
041        super(ALGORITHM_NAME);
042    }
043
044    public Sha1Hash(Object source) {
045        super(ALGORITHM_NAME, source);
046    }
047
048    public Sha1Hash(Object source, Object salt) {
049        super(ALGORITHM_NAME, source, salt);
050    }
051
052    public Sha1Hash(Object source, Object salt, int hashIterations) {
053        super(ALGORITHM_NAME, source, salt, hashIterations);
054    }
055
056    public static Sha1Hash fromHexString(String hex) {
057        Sha1Hash hash = new Sha1Hash();
058        hash.setBytes(Hex.decode(hex));
059        return hash;
060    }
061
062    public static Sha1Hash fromBase64String(String base64) {
063        Sha1Hash hash = new Sha1Hash();
064        hash.setBytes(Base64.decode(base64));
065        return hash;
066    }
067}