View Javadoc
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  
18  package org.apache.commons.codec.digest;
19  
20  import java.security.MessageDigest;
21  
22  /**
23   * Standard {@link MessageDigest} algorithm names from the <cite>Java Cryptography Architecture Standard Algorithm Name
24   * Documentation</cite>.
25   * <p>
26   * This class is immutable and thread-safe.
27   * </p>
28   * <ul>
29   * <li>Java 8 and up: SHA-224.</li>
30   * <li>Java 9 and up: SHA3-224, SHA3-256, SHA3-384, SHA3-512.</li>
31   * </ul>
32   *
33   * @see <a href="https://docs.oracle.com/javase/8/docs/technotes/guides/security/StandardNames.html#MessageDigest">
34   *      Java 8 Cryptography Architecture Standard Algorithm Name Documentation</a>
35   * @see <a href="https://docs.oracle.com/en/java/javase/11/docs/specs/security/standard-names.html#messagedigest-algorithms">
36   *      Java 11 Cryptography Architecture Standard Algorithm Name Documentation</a>
37   * @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/security/standard-names.html#messagedigest-algorithms">
38   *      Java 17 Cryptography Architecture Standard Algorithm Name Documentation</a>
39   * @see <a href="https://docs.oracle.com/en/java/javase/21/docs/specs/security/standard-names.html#messagedigest-algorithms">
40   *      Java 21 Cryptography Architecture Standard Algorithm Name Documentation</a>
41   *
42   * @see <a href="https://dx.doi.org/10.6028/NIST.FIPS.180-4">FIPS PUB 180-4</a>
43   * @see <a href="https://dx.doi.org/10.6028/NIST.FIPS.202">FIPS PUB 202</a>
44   * @since 1.7
45   */
46  public class MessageDigestAlgorithms {
47  
48      /**
49       * The MD2 message digest algorithm defined in RFC 1319.
50       */
51      public static final String MD2 = "MD2";
52  
53      /**
54       * The MD5 message digest algorithm defined in RFC 1321.
55       */
56      public static final String MD5 = "MD5";
57  
58      /**
59       * The SHA-1 hash algorithm defined in the FIPS PUB 180-2.
60       */
61      public static final String SHA_1 = "SHA-1";
62  
63      /**
64       * The SHA-224 hash algorithm defined in the FIPS PUB 180-3.
65       * <p>
66       * Present in Oracle Java 8.
67       * </p>
68       *
69       * @since 1.11
70       */
71      public static final String SHA_224 = "SHA-224";
72  
73      /**
74       * The SHA-256 hash algorithm defined in the FIPS PUB 180-2.
75       */
76      public static final String SHA_256 = "SHA-256";
77  
78      /**
79       * The SHA-384 hash algorithm defined in the FIPS PUB 180-2.
80       */
81      public static final String SHA_384 = "SHA-384";
82  
83      /**
84       * The SHA-512 hash algorithm defined in the FIPS PUB 180-2.
85       */
86      public static final String SHA_512 = "SHA-512";
87  
88      /**
89       * The SHA-512 hash algorithm defined in the FIPS PUB 180-4.
90       * <p>
91       * Included starting in Oracle Java 9.
92       * </p>
93       *
94       * @since 1.14
95       */
96      public static final String SHA_512_224 = "SHA-512/224";
97  
98      /**
99       * The SHA-512 hash algorithm defined in the FIPS PUB 180-4.
100      * <p>
101      * Included starting in Oracle Java 9.
102      * </p>
103      *
104      * @since 1.14
105      */
106     public static final String SHA_512_256 = "SHA-512/256";
107 
108     /**
109      * The SHA3-224 hash algorithm defined in the FIPS PUB 202.
110      * <p>
111      * Included starting in Oracle Java 9.
112      * </p>
113      *
114      * @since 1.11
115      */
116     public static final String SHA3_224 = "SHA3-224";
117 
118     /**
119      * The SHA3-256 hash algorithm defined in the FIPS PUB 202.
120      * <p>
121      * Included starting in Oracle Java 9.
122      * </p>
123      *
124      * @since 1.11
125      */
126     public static final String SHA3_256 = "SHA3-256";
127 
128     /**
129      * The SHA3-384 hash algorithm defined in the FIPS PUB 202.
130      * <p>
131      * Included starting in Oracle Java 9.
132      * </p>
133      *
134      * @since 1.11
135      */
136     public static final String SHA3_384 = "SHA3-384";
137 
138     /**
139      * The SHA3-512 hash algorithm defined in the FIPS PUB 202.
140      * <p>
141      * Included starting in Oracle Java 9.
142      * </p>
143      *
144      * @since 1.11
145      */
146     public static final String SHA3_512 = "SHA3-512";
147 
148     /**
149      * Gets all constant values defined in this class.
150      *
151      * @return all constant values defined in this class.
152      * @since 1.11
153      */
154     public static String[] values() {
155         // Do not use a constant array here as that can be changed externally by accident or design
156         return new String[] {
157             MD2, MD5, SHA_1, SHA_224, SHA_256, SHA_384,
158             SHA_512, SHA_512_224, SHA_512_256, SHA3_224, SHA3_256, SHA3_384, SHA3_512
159         };
160     }
161 
162     private MessageDigestAlgorithms() {
163         // cannot be instantiated.
164     }
165 
166 }