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