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