HmacAlgorithms.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The ASF licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *      https://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */

  17. package org.apache.commons.codec.digest;

  18. /**
  19.  * Standard {@link HmacUtils} algorithm names from the <cite>Java Cryptography Architecture Standard Algorithm Name
  20.  * Documentation</cite>.
  21.  *
  22.  * <p>
  23.  * <strong>Note: Not all JCE implementations support all the algorithms in this enum.</strong>
  24.  * </p>
  25.  *
  26.  * @see <a href="https://docs.oracle.com/javase/8/docs/technotes/guides/security/SunProviders.html#SunJCEProvider"> Java
  27.  *      8 Cryptography Architecture Sun Providers Documentation</a>
  28.  * @see <a href=
  29.  *      "https://docs.oracle.com/en/java/javase/11/security/oracle-providers.html#GUID-A47B1249-593C-4C38-A0D0-68FA7681E0A7">
  30.  *      Java 11 Cryptography Architecture Sun Providers Documentation</a>
  31.  * @see <a href=
  32.  *      "https://docs.oracle.com/en/java/javase/17/security/oracle-providers.html#GUID-A47B1249-593C-4C38-A0D0-68FA7681E0A7">
  33.  *      Java 17 Cryptography Architecture Sun Providers Documentation</a>
  34.  *
  35.  * @since 1.10
  36.  */
  37. public enum HmacAlgorithms {

  38.     /**
  39.      * The HmacMD5 Message Authentication Code (MAC) algorithm specified in RFC 2104 and RFC 1321.
  40.      * <p>
  41.      * Every implementation of the Java platform is required to support this standard MAC algorithm.
  42.      * </p>
  43.      */
  44.     HMAC_MD5("HmacMD5"),

  45.     /**
  46.      * The HmacSHA1 Message Authentication Code (MAC) algorithm specified in RFC 2104 and FIPS PUB 180-2.
  47.      * <p>
  48.      * Every implementation of the Java platform is required to support this standard MAC algorithm.
  49.      * </p>
  50.      */
  51.     HMAC_SHA_1("HmacSHA1"),

  52.     /**
  53.      * The HmacSHA224 Message Authentication Code (MAC) algorithm specified in RFC 2104 and FIPS PUB 180-2.
  54.      * <p>
  55.      * Every implementation of the Java 8+ platform is required to support this standard MAC algorithm.
  56.      * </p>
  57.      * @since 1.11
  58.      */
  59.     HMAC_SHA_224("HmacSHA224"),

  60.     /**
  61.      * The HmacSHA256 Message Authentication Code (MAC) algorithm specified in RFC 2104 and FIPS PUB 180-2.
  62.      * <p>
  63.      * Every implementation of the Java platform is required to support this standard MAC algorithm.
  64.      * </p>
  65.      */
  66.     HMAC_SHA_256("HmacSHA256"),

  67.     /**
  68.      * The HmacSHA384 Message Authentication Code (MAC) algorithm specified in RFC 2104 and FIPS PUB 180-2.
  69.      * <p>
  70.      * This MAC algorithm is <em>optional</em>; not all implementations support it.
  71.      * </p>
  72.      */
  73.     HMAC_SHA_384("HmacSHA384"),

  74.     /**
  75.      * The HmacSHA512 Message Authentication Code (MAC) algorithm specified in RFC 2104 and FIPS PUB 180-2.
  76.      * <p>
  77.      * This MAC algorithm is <em>optional</em>; not all implementations support it.
  78.      * </p>
  79.      */
  80.     HMAC_SHA_512("HmacSHA512");

  81.     private final String name;

  82.     HmacAlgorithms(final String algorithm) {
  83.         this.name = algorithm;
  84.     }

  85.     /**
  86.      * Gets the algorithm name.
  87.      *
  88.      * @return the algorithm name.
  89.      * @since 1.11
  90.      */
  91.     public String getName() {
  92.         return name;
  93.     }

  94.     /**
  95.      * The algorithm name.
  96.      *
  97.      * @see <a href="https://docs.oracle.com/javase/6/docs/technotes/guides/security/SunProviders.html#SunJCEProvider">
  98.      *      Java 6 Cryptography Architecture Sun Providers Documentation</a>
  99.      * @see <a href="https://docs.oracle.com/javase/7/docs/technotes/guides/security/SunProviders.html#SunJCEProvider">
  100.      *      Java 7 Cryptography Architecture Sun Providers Documentation</a>
  101.      * @see <a href="https://docs.oracle.com/javase/8/docs/technotes/guides/security/SunProviders.html#SunJCEProvider">
  102.      *      Java 8 Cryptography Architecture Sun Providers Documentation</a>
  103.      * @see <a href=
  104.      *      "https://docs.oracle.com/javase/9/security/oracleproviders.htm#JSSEC-GUID-A47B1249-593C-4C38-A0D0-68FA7681E0A7">
  105.      *      Java 9 Cryptography Architecture Sun Providers Documentation</a>
  106.      * @return The algorithm name ("HmacSHA512" for example)
  107.      */
  108.     @Override
  109.     public String toString() {
  110.         return name;
  111.     }

  112. }