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.  *      http://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="http://docs.oracle.com/javase/6/docs/technotes/guides/security/SunProviders.html#SunJCEProvider"> Java
  27.  *      6 Cryptography Architecture Sun Providers Documentation</a>
  28.  * @see <a href="http://docs.oracle.com/javase/7/docs/technotes/guides/security/SunProviders.html#SunJCEProvider"> Java
  29.  *      7 Cryptography Architecture Sun Providers Documentation</a>
  30.  * @see <a href="http://docs.oracle.com/javase/8/docs/technotes/guides/security/SunProviders.html#SunJCEProvider"> Java
  31.  *      8 Cryptography Architecture Sun Providers Documentation</a>
  32.  * @see <a href=
  33.  *      "http://docs.oracle.com/javase/9/security/oracleproviders.htm#JSSEC-GUID-A47B1249-593C-4C38-A0D0-68FA7681E0A7">
  34.  *      Java 9 Cryptography Architecture Sun Providers Documentation</a>
  35.  * @since 1.10
  36.  * @version $Id: HmacAlgorithms.java 1811624 2017-10-09 23:07:49Z ggregory $
  37.  */
  38. public enum HmacAlgorithms {

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

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

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

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

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

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

  82.     private final String name;

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

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

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

  113. }