    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 *      https://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="https://docs.oracle.com/javase/8/docs/technotes/guides/security/StandardNames.html#MessageDigest">
    034 *      Java 8 Cryptography Architecture Standard Algorithm Name Documentation</a>
    035 * @see <a href="https://docs.oracle.com/en/java/javase/11/docs/specs/security/standard-names.html#messagedigest-algorithms">
    036 *      Java 11 Cryptography Architecture Standard Algorithm Name Documentation</a>
    037 * @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/security/standard-names.html#messagedigest-algorithms">
    038 *      Java 17 Cryptography Architecture Standard Algorithm Name Documentation</a>
    039 * @see <a href="https://docs.oracle.com/en/java/javase/21/docs/specs/security/standard-names.html#messagedigest-algorithms">
    040 *      Java 21 Cryptography Architecture Standard Algorithm Name Documentation</a>
    041 * @see <a href="https://docs.oracle.com/en/java/javase/25/docs/specs/security/standard-names.html#messagedigest-algorithms">
    042 *      Java 25 Cryptography Architecture Standard Algorithm Name Documentation</a>
    043 *
    044 * @see <a href="https://dx.doi.org/10.6028/NIST.FIPS.180-4">FIPS PUB 180-4</a>
    045 * @see <a href="https://dx.doi.org/10.6028/NIST.FIPS.202">FIPS PUB 202</a>
    046 * @since 1.7
    047 */
    048public class MessageDigestAlgorithms {
    049
    050    /**
    051     * The MD2 message digest algorithm defined in RFC 1319.
    052     */
    053    public static final String MD2 = "MD2";
    054
    055    /**
    056     * The MD5 message digest algorithm defined in RFC 1321.
    057     */
    058    public static final String MD5 = "MD5";
    059
    060    /**
    061     * The SHA-1 hash algorithm defined in the FIPS PUB 180-2.
    062     */
    063    public static final String SHA_1 = "SHA-1";
    064
    065    /**
    066     * The SHA-224 hash algorithm defined in the FIPS PUB 180-3.
    067     * <p>
    068     * Present in Oracle Java 8.
    069     * </p>
    070     *
    071     * @since 1.11
    072     */
    073    public static final String SHA_224 = "SHA-224";
    074
    075    /**
    076     * The SHA-256 hash algorithm defined in the FIPS PUB 180-2.
    077     */
    078    public static final String SHA_256 = "SHA-256";
    079
    080    /**
    081     * The SHA-384 hash algorithm defined in the FIPS PUB 180-2.
    082     */
    083    public static final String SHA_384 = "SHA-384";
    084
    085    /**
    086     * The SHA-512 hash algorithm defined in the FIPS PUB 180-2.
    087     */
    088    public static final String SHA_512 = "SHA-512";
    089
    090    /**
    091     * The SHA-512 hash algorithm defined in the FIPS PUB 180-4.
    092     * <p>
    093     * Included starting in Oracle Java 9.
    094     * </p>
    095     *
    096     * @since 1.14
    097     */
    098    public static final String SHA_512_224 = "SHA-512/224";
    099
    100    /**
    101     * The SHA-512 hash algorithm defined in the FIPS PUB 180-4.
    102     * <p>
    103     * Included starting in Oracle Java 9.
    104     * </p>
    105     *
    106     * @since 1.14
    107     */
    108    public static final String SHA_512_256 = "SHA-512/256";
    109
    110    /**
    111     * The SHA3-224 hash algorithm defined in the <a href="https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf">FIPS PUB 202</a>.
    112     * <p>
    113     * Included starting in Oracle Java 9.
    114     * </p>
    115     *
    116     * @since 1.11
    117     */
    118    public static final String SHA3_224 = "SHA3-224";
    119
    120    /**
    121     * The SHA3-256 hash algorithm defined in the <a href="https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf">FIPS PUB 202</a>.
    122     * <p>
    123     * Included starting in Oracle Java 9.
    124     * </p>
    125     *
    126     * @since 1.11
    127     */
    128    public static final String SHA3_256 = "SHA3-256";
    129
    130    /**
    131     * The SHA3-384 hash algorithm defined in the <a href="https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf">FIPS PUB 202</a>.
    132     * <p>
    133     * Included starting in Oracle Java 9.
    134     * </p>
    135     *
    136     * @since 1.11
    137     */
    138    public static final String SHA3_384 = "SHA3-384";
    139
    140    /**
    141     * The SHA3-512 hash algorithm defined in the <a href="https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf">FIPS PUB 202</a>.
    142     * <p>
    143     * Included starting in Oracle Java 9.
    144     * </p>
    145     *
    146     * @since 1.11
    147     */
    148    public static final String SHA3_512 = "SHA3-512";
    149
    150    /**
    151     * The SHAKE128-256 hash algorithm defined in the <a href="https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf">FIPS PUB 202</a>.
    152     * <p>
    153     * Included starting in Oracle Java 25.
    154     * </p>
    155     *
    156     * @see <a href="https://docs.oracle.com/en/java/javase/25/docs/specs/security/standard-names.html#messagedigest-algorithms"> Java 25 Cryptography
    157     *      Architecture Standard Algorithm Name Documentation</a>
    158     * @see <a href="https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf">FIPS PUB 202 - SHA-3 Standard: Permutation-Based Hash and Extendable-Output
    159     *      Functions</a>
    160     * @since 1.20.0
    161     */
    162    public static final String SHAKE128_256 = "SHAKE128-256";
    163
    164    /**
    165     * The SHAKE128-512 hash algorithm defined in the <a href="https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf">FIPS PUB 202</a>.
    166     * <p>
    167     * Included starting in Oracle Java 25.
    168     * </p>
    169     *
    170     * @see <a href="https://docs.oracle.com/en/java/javase/25/docs/specs/security/standard-names.html#messagedigest-algorithms"> Java 25 Cryptography
    171     *      Architecture Standard Algorithm Name Documentation</a>
    172     * @see <a href="https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf">FIPS PUB 202 - SHA-3 Standard: Permutation-Based Hash and Extendable-Output
    173     *      Functions</a>
    174     * @since 1.20.0
    175     */
    176    public static final String SHAKE256_512 = "SHAKE256-512";
    177
    178    /**
    179     * Gets all constant values defined in this class.
    180     *
    181     * @return all constant values defined in this class.
    182     * @since 1.11
    183     */
    184    public static String[] values() {
    185        // Do not use a constant array here as that can be changed externally by accident or design
    186        return new String[] { MD2, MD5, SHA_1, SHA_224, SHA_256, SHA_384, SHA_512, SHA_512_224, SHA_512_256, SHA3_224, SHA3_256, SHA3_384, SHA3_512,
    187                SHAKE128_256, SHAKE256_512 };
    188    }
    189
    190    private MessageDigestAlgorithms() {
    191        // cannot be instantiated.
    192    }
    193
    194}