MessageDigestAlgorithms.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. import java.security.MessageDigest;

  19. /**
  20.  * Standard {@link MessageDigest} algorithm names from the <cite>Java Cryptography Architecture Standard Algorithm Name
  21.  * Documentation</cite>.
  22.  * <p>
  23.  * This class is immutable and thread-safe.
  24.  * </p>
  25.  * <p>
  26.  * Java 8 and up: SHA-224.
  27.  * </p>
  28.  * <p>
  29.  * Java 9 and up: SHA3-224, SHA3-256, SHA3-384, SHA3-512.
  30.  * </p>
  31.  *
  32.  * @see <a href="http://docs.oracle.com/javase/6/docs/technotes/guides/security/StandardNames.html#MessageDigest">
  33.  *      Java 6 Cryptography Architecture Standard Algorithm Name Documentation</a>
  34.  * @see <a href="http://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#MessageDigest">
  35.  *      Java 7 Cryptography Architecture Standard Algorithm Name Documentation</a>
  36.  * @see <a href="http://docs.oracle.com/javase/8/docs/technotes/guides/security/StandardNames.html#MessageDigest">
  37.  *      Java 8 Cryptography Architecture Standard Algorithm Name Documentation</a>
  38.  * @see <a href="http://download.java.net/java/jdk9/docs/technotes/guides/security/StandardNames.html#MessageDigest">
  39.  *      Java 9 Cryptography Architecture Standard Algorithm Name Documentation</a>
  40.  *
  41.  * @see <a href="http://dx.doi.org/10.6028/NIST.FIPS.180-4">FIPS PUB 180-4</a>
  42.  * @see <a href="http://dx.doi.org/10.6028/NIST.FIPS.202">FIPS PUB 202</a>
  43.  * @since 1.7
  44.  * @version $Id: MessageDigestAlgorithms.java 1744728 2016-05-20 12:55:58Z sebb $
  45.  */
  46. public class MessageDigestAlgorithms {

  47.     /**
  48.      * The MD2 message digest algorithm defined in RFC 1319.
  49.      */
  50.     public static final String MD2 = "MD2";

  51.     /**
  52.      * The MD5 message digest algorithm defined in RFC 1321.
  53.      */
  54.     public static final String MD5 = "MD5";

  55.     /**
  56.      * The SHA-1 hash algorithm defined in the FIPS PUB 180-2.
  57.      */
  58.     public static final String SHA_1 = "SHA-1";

  59.     /**
  60.      * The SHA-224 hash algorithm defined in the FIPS PUB 180-3.
  61.      * <p>
  62.      * Present in Oracle Java 8.
  63.      * </p>
  64.      *
  65.      * @since 1.11
  66.      */
  67.     public static final String SHA_224 = "SHA-224";

  68.     /**
  69.      * The SHA-256 hash algorithm defined in the FIPS PUB 180-2.
  70.      */
  71.     public static final String SHA_256 = "SHA-256";

  72.     /**
  73.      * The SHA-384 hash algorithm defined in the FIPS PUB 180-2.
  74.      */
  75.     public static final String SHA_384 = "SHA-384";

  76.     /**
  77.      * The SHA-512 hash algorithm defined in the FIPS PUB 180-2.
  78.      */
  79.     public static final String SHA_512 = "SHA-512";

  80.     /**
  81.      * The SHA3-224 hash algorithm defined in the FIPS PUB 202.
  82.      * <p>
  83.      * Likely to be included in Oracle Java 9 GA.
  84.      * </p>
  85.      *
  86.      * @since 1.11
  87.      */
  88.     public static final String SHA3_224 = "SHA3-224";

  89.     /**
  90.      * The SHA3-256 hash algorithm defined in the FIPS PUB 202.
  91.      * <p>
  92.      * Likely to be included in Oracle Java 9 GA.
  93.      * </p>
  94.      *
  95.      * @since 1.11
  96.      */
  97.     public static final String SHA3_256 = "SHA3-256";

  98.     /**
  99.      * The SHA3-384 hash algorithm defined in the FIPS PUB 202.
  100.      * <p>
  101.      * Likely to be included in Oracle Java 9 GA.
  102.      * </p>
  103.      *
  104.      * @since 1.11
  105.      */
  106.     public static final String SHA3_384 = "SHA3-384";

  107.     /**
  108.      * The SHA3-512 hash algorithm defined in the FIPS PUB 202.
  109.      * <p>
  110.      * Likely to be included in Oracle Java 9 GA.
  111.      * </p>
  112.      *
  113.      * @since 1.11
  114.      */
  115.     public static final String SHA3_512 = "SHA3-512";

  116.     /**
  117.      * Gets all constant values defined in this class.
  118.      *
  119.      * @return all constant values defined in this class.
  120.      * @since 1.11
  121.      */
  122.     public static String[] values() {
  123.         // N.B. do not use a constant array here as that can be changed externally by accident or design
  124.         return new String[] {
  125.             MD2, MD5, SHA_1, SHA_224, SHA_256, SHA_384, SHA_512, SHA3_224, SHA3_256, SHA3_384, SHA3_512
  126.         };
  127.     }

  128.     private MessageDigestAlgorithms() {
  129.         // cannot be instantiated.
  130.     }

  131. }