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 *      http://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
020import java.security.MessageDigest;
021
022/**
023 * Standard {@link MessageDigest} algorithm names from the <cite>Java Cryptography Architecture Standard Algorithm Name
024 * Documentation</cite>.
025 * <p>
026 * This class is immutable and thread-safe.
027 * </p>
028 * <ul>
029 * <li>Java 8 and up: SHA-224.</li>
030 * <li>Java 9 and up: SHA3-224, SHA3-256, SHA3-384, SHA3-512.</li>
031 * </ul>
032 *
033 * @see <a href="http://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#MessageDigest">
034 *      Java 7 Cryptography Architecture Standard Algorithm Name Documentation</a>
035 * @see <a href="http://docs.oracle.com/javase/8/docs/technotes/guides/security/StandardNames.html#MessageDigest">
036 *      Java 8 Cryptography Architecture Standard Algorithm Name Documentation</a>
037 * @see <a href="https://docs.oracle.com/javase/9/docs/specs/security/standard-names.html#messagedigest-algorithms">
038 *      Java 9 Cryptography Architecture Standard Algorithm Name Documentation</a>
039 * @see <a href="https://docs.oracle.com/javase/10/docs/specs/security/standard-names.html#messagedigest-algorithms">
040 *      Java 10 Cryptography Architecture Standard Algorithm Name Documentation</a>
041 * @see <a href="https://docs.oracle.com/en/java/javase/11/docs/specs/security/standard-names.html#messagedigest-algorithms">
042 *      Java 11 Cryptography Architecture Standard Algorithm Name Documentation</a>
043 * @see <a href="https://docs.oracle.com/en/java/javase/12/docs/specs/security/standard-names.html#messagedigest-algorithms">
044 *      Java 12 Cryptography Architecture Standard Algorithm Name Documentation</a>
045 * @see <a href="https://docs.oracle.com/en/java/javase/13/docs/specs/security/standard-names.html#messagedigest-algorithms">
046 *      Java 13 Cryptography Architecture Standard Algorithm Name Documentation</a>
047 * @see <a href="https://docs.oracle.com/en/java/javase/14/docs/specs/security/standard-names.html#messagedigest-algorithms">
048 *      Java 14 Cryptography Architecture Standard Algorithm Name Documentation</a>
049 * @see <a href="https://docs.oracle.com/en/java/javase/15/docs/specs/security/standard-names.html#messagedigest-algorithms">
050 *      Java 15 Cryptography Architecture Standard Algorithm Name Documentation</a>
051 * @see <a href="https://docs.oracle.com/en/java/javase/16/docs/specs/security/standard-names.html#messagedigest-algorithms">
052 *      Java 16 Cryptography Architecture Standard Algorithm Name Documentation</a>
053 * @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/security/standard-names.html#messagedigest-algorithms">
054 *      Java 17 Cryptography Architecture Standard Algorithm Name Documentation</a>
055 * @see <a href="https://docs.oracle.com/en/java/javase/18/docs/specs/security/standard-names.html#messagedigest-algorithms">
056 *      Java 18 Cryptography Architecture Standard Algorithm Name Documentation</a>
057 * @see <a href="https://docs.oracle.com/en/java/javase/19/docs/specs/security/standard-names.html#messagedigest-algorithms">
058 *      Java 19 Cryptography Architecture Standard Algorithm Name Documentation</a>
059 * @see <a href="https://docs.oracle.com/en/java/javase/20/docs/specs/security/standard-names.html#messagedigest-algorithms">
060 *      Java 20 Cryptography Architecture Standard Algorithm Name Documentation</a>
061 *
062 * @see <a href="http://dx.doi.org/10.6028/NIST.FIPS.180-4">FIPS PUB 180-4</a>
063 * @see <a href="http://dx.doi.org/10.6028/NIST.FIPS.202">FIPS PUB 202</a>
064 * @since 1.7
065 */
066public class MessageDigestAlgorithms {
067
068    /**
069     * The MD2 message digest algorithm defined in RFC 1319.
070     */
071    public static final String MD2 = "MD2";
072
073    /**
074     * The MD5 message digest algorithm defined in RFC 1321.
075     */
076    public static final String MD5 = "MD5";
077
078    /**
079     * The SHA-1 hash algorithm defined in the FIPS PUB 180-2.
080     */
081    public static final String SHA_1 = "SHA-1";
082
083    /**
084     * The SHA-224 hash algorithm defined in the FIPS PUB 180-3.
085     * <p>
086     * Present in Oracle Java 8.
087     * </p>
088     *
089     * @since 1.11
090     */
091    public static final String SHA_224 = "SHA-224";
092
093    /**
094     * The SHA-256 hash algorithm defined in the FIPS PUB 180-2.
095     */
096    public static final String SHA_256 = "SHA-256";
097
098    /**
099     * The SHA-384 hash algorithm defined in the FIPS PUB 180-2.
100     */
101    public static final String SHA_384 = "SHA-384";
102
103    /**
104     * The SHA-512 hash algorithm defined in the FIPS PUB 180-2.
105     */
106    public static final String SHA_512 = "SHA-512";
107
108    /**
109     * The SHA-512 hash algorithm defined in the FIPS PUB 180-4.
110     * <p>
111     * Included starting in Oracle Java 9.
112     * </p>
113     *
114     * @since 1.14
115     */
116    public static final String SHA_512_224 = "SHA-512/224";
117
118    /**
119     * The SHA-512 hash algorithm defined in the FIPS PUB 180-4.
120     * <p>
121     * Included starting in Oracle Java 9.
122     * </p>
123     *
124     * @since 1.14
125     */
126    public static final String SHA_512_256 = "SHA-512/256";
127
128    /**
129     * The SHA3-224 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_224 = "SHA3-224";
137
138    /**
139     * The SHA3-256 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_256 = "SHA3-256";
147
148    /**
149     * The SHA3-384 hash algorithm defined in the FIPS PUB 202.
150     * <p>
151     * Included starting in Oracle Java 9.
152     * </p>
153     *
154     * @since 1.11
155     */
156    public static final String SHA3_384 = "SHA3-384";
157
158    /**
159     * The SHA3-512 hash algorithm defined in the FIPS PUB 202.
160     * <p>
161     * Included starting in Oracle Java 9.
162     * </p>
163     *
164     * @since 1.11
165     */
166    public static final String SHA3_512 = "SHA3-512";
167
168    /**
169     * Gets all constant values defined in this class.
170     *
171     * @return all constant values defined in this class.
172     * @since 1.11
173     */
174    public static String[] values() {
175        // N.B. do not use a constant array here as that can be changed externally by accident or design
176        return new String[] {
177            MD2, MD5, SHA_1, SHA_224, SHA_256, SHA_384,
178            SHA_512, SHA_512_224, SHA_512_256, SHA3_224, SHA3_256, SHA3_384, SHA3_512
179        };
180    }
181
182    private MessageDigestAlgorithms() {
183        // cannot be instantiated.
184    }
185
186}