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 MD2 Hash (RFC 1319) from a given input <tt>source</tt> with an optional <tt>salt</tt> and
027 * 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 Md2Hash extends SimpleHash {
035
036    public static final String ALGORITHM_NAME = "MD2";
037
038    public Md2Hash() {
039        super(ALGORITHM_NAME);
040    }
041
042    public Md2Hash(Object source) {
043        super(ALGORITHM_NAME, source);
044    }
045
046    public Md2Hash(Object source, Object salt) {
047        super(ALGORITHM_NAME, source, salt);
048    }
049
050    public Md2Hash(Object source, Object salt, int hashIterations) {
051        super(ALGORITHM_NAME, source, salt, hashIterations);
052    }
053
054    public static Md2Hash fromHexString(String hex) {
055        Md2Hash hash = new Md2Hash();
056        hash.setBytes(Hex.decode(hex));
057        return hash;
058    }
059
060    public static Md2Hash fromBase64String(String base64) {
061        Md2Hash hash = new Md2Hash();
062        hash.setBytes(Base64.decode(base64));
063        return hash;
064    }
065}