    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one or more
    003 * contributor license agreements.  See the NOTICE file distributed with
    004 * this work for additional information regarding copyright ownership.
    005 * The ASF licenses this file to You under the Apache License, Version 2.0
    006 * (the "License"); you may not use this file except in compliance with
    007 * the License.  You may obtain a copy of the License at
    008 *
    009 *      https://www.apache.org/licenses/LICENSE-2.0
    010 *
    011 * Unless required by applicable law or agreed to in writing, software
    012 * distributed under the License is distributed on an "AS IS" BASIS,
    013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014 * See the License for the specific language governing permissions and
    015 * limitations under the License.
    016 */
    017
    018package org.apache.commons.codec.digest;
    019
    020/**
    021 * Standard {@link HmacUtils} algorithm names from the <cite>Java Cryptography Architecture Standard Algorithm Name
    022 * Documentation</cite>.
    023 *
    024 * <p>
    025 * <strong>Note: Not all JCE implementations support all the algorithms in this enum.</strong>
    026 * </p>
    027 *
    028 * @see <a href="https://docs.oracle.com/javase/8/docs/technotes/guides/security/SunProviders.html#SunJCEProvider"> Java
    029 *      8 Cryptography Architecture Sun Providers Documentation</a>
    030 * @see <a href=
    031 *      "https://docs.oracle.com/en/java/javase/11/security/oracle-providers.html#GUID-A47B1249-593C-4C38-A0D0-68FA7681E0A7">
    032 *      Java 11 Cryptography Architecture Sun Providers Documentation</a>
    033 * @see <a href=
    034 *      "https://docs.oracle.com/en/java/javase/17/security/oracle-providers.html#GUID-A47B1249-593C-4C38-A0D0-68FA7681E0A7">
    035 *      Java 17 Cryptography Architecture Sun Providers Documentation</a>
    036 *
    037 * @since 1.10
    038 */
    039public enum HmacAlgorithms {
    040
    041    /**
    042     * The HmacMD5 Message Authentication Code (MAC) algorithm specified in RFC 2104 and RFC 1321.
    043     * <p>
    044     * Every implementation of the Java platform is required to support this standard MAC algorithm.
    045     * </p>
    046     */
    047    HMAC_MD5("HmacMD5"),
    048
    049    /**
    050     * The HmacSHA1 Message Authentication Code (MAC) algorithm specified in RFC 2104 and FIPS PUB 180-2.
    051     * <p>
    052     * Every implementation of the Java platform is required to support this standard MAC algorithm.
    053     * </p>
    054     */
    055    HMAC_SHA_1("HmacSHA1"),
    056
    057    /**
    058     * The HmacSHA224 Message Authentication Code (MAC) algorithm specified in RFC 2104 and FIPS PUB 180-2.
    059     * <p>
    060     * Every implementation of the Java 8+ platform is required to support this standard MAC algorithm.
    061     * </p>
    062     *
    063     * @since 1.11
    064     */
    065    HMAC_SHA_224("HmacSHA224"),
    066
    067    /**
    068     * The HmacSHA256 Message Authentication Code (MAC) algorithm specified in RFC 2104 and FIPS PUB 180-2.
    069     * <p>
    070     * Every implementation of the Java platform is required to support this standard MAC algorithm.
    071     * </p>
    072     */
    073    HMAC_SHA_256("HmacSHA256"),
    074
    075    /**
    076     * The HmacSHA384 Message Authentication Code (MAC) algorithm specified in RFC 2104 and FIPS PUB 180-2.
    077     * <p>
    078     * This MAC algorithm is <em>optional</em>; not all implementations support it.
    079     * </p>
    080     */
    081    HMAC_SHA_384("HmacSHA384"),
    082
    083    /**
    084     * The HmacSHA512 Message Authentication Code (MAC) algorithm specified in RFC 2104 and FIPS PUB 180-2.
    085     * <p>
    086     * This MAC algorithm is <em>optional</em>; not all implementations support it.
    087     * </p>
    088     */
    089    HMAC_SHA_512("HmacSHA512");
    090
    091    private final String name;
    092
    093    HmacAlgorithms(final String algorithm) {
    094        this.name = algorithm;
    095    }
    096
    097    /**
    098     * Gets the algorithm name.
    099     *
    100     * @return the algorithm name.
    101     * @since 1.11
    102     */
    103    public String getName() {
    104        return name;
    105    }
    106
    107    /**
    108     * The algorithm name.
    109     *
    110     * @see <a href="https://docs.oracle.com/javase/8/docs/technotes/guides/security/SunProviders.html#SunJCEProvider">
    111     *      Java 8 Cryptography Architecture Sun Providers Documentation</a>
    112     * @see <a href=
    113     *      "https://docs.oracle.com/javase/9/security/oracleproviders.htm#JSSEC-GUID-A47B1249-593C-4C38-A0D0-68FA7681E0A7">
    114     *      Java 9 Cryptography Architecture Sun Providers Documentation</a>
    115     * @return The algorithm name ("HmacSHA512" for example).
    116     */
    117    @Override
    118    public String toString() {
    119        return name;
    120    }
    121
    122}