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 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 AbstractHash AbstractHash} parent class JavaDoc for a detailed explanation of Hashing
030     * techniques and how the overloaded constructors function.
031     *
032     * @author Les Hazlewood
033     * @since 0.9
034     */
035    public class Md2Hash extends AbstractHash {
036    
037        //TODO - complete JavaDoc
038    
039        public static final String ALGORITHM_NAME = "MD2";
040    
041        public Md2Hash() {
042        }
043    
044        public Md2Hash(Object source) {
045            super(source);
046        }
047    
048        public Md2Hash(Object source, Object salt) {
049            super(source, salt);
050        }
051    
052        public Md2Hash(Object source, Object salt, int hashIterations) {
053            super(source, salt, hashIterations);
054        }
055    
056        protected String getAlgorithmName() {
057            return ALGORITHM_NAME;
058        }
059    
060        public static Md2Hash fromHexString(String hex) {
061            Md2Hash hash = new Md2Hash();
062            hash.setBytes(Hex.decode(hex));
063            return hash;
064        }
065    
066        public static Md2Hash fromBase64String(String base64) {
067            Md2Hash hash = new Md2Hash();
068            hash.setBytes(Base64.decode(base64));
069            return hash;
070        }
071    }