Skip to content

Commit 01a0540

Browse files
committed
Refactor strings into a new class MessageDigestAlgorithms for public consumption.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/codec/trunk@1379769 13f79535-47bb-0310-9956-ffa450edef68
1 parent f5b26b6 commit 01a0540

2 files changed

Lines changed: 67 additions & 4 deletions

File tree

src/main/java/org/apache/commons/codec/digest/DigestUtils.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public static MessageDigest getDigest(String algorithm) {
9797
* when a {@link java.security.NoSuchAlgorithmException} is caught.
9898
*/
9999
public static MessageDigest getMd5Digest() {
100-
return getDigest("MD5");
100+
return getDigest(MessageDigestAlgorithms.MD5);
101101
}
102102

103103
/**
@@ -111,7 +111,7 @@ public static MessageDigest getMd5Digest() {
111111
* when a {@link java.security.NoSuchAlgorithmException} is caught.
112112
*/
113113
public static MessageDigest getSha256Digest() {
114-
return getDigest("SHA-256");
114+
return getDigest(MessageDigestAlgorithms.SHA_256);
115115
}
116116

117117
/**
@@ -125,7 +125,7 @@ public static MessageDigest getSha256Digest() {
125125
* when a {@link java.security.NoSuchAlgorithmException} is caught.
126126
*/
127127
public static MessageDigest getSha384Digest() {
128-
return getDigest("SHA-384");
128+
return getDigest(MessageDigestAlgorithms.SHA_384);
129129
}
130130

131131
/**
@@ -139,7 +139,7 @@ public static MessageDigest getSha384Digest() {
139139
* when a {@link java.security.NoSuchAlgorithmException} is caught.
140140
*/
141141
public static MessageDigest getSha512Digest() {
142-
return getDigest("SHA-512");
142+
return getDigest(MessageDigestAlgorithms.SHA_512);
143143
}
144144

145145
/**
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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
24+
* Name Documentation</cite>.
25+
*
26+
* @see <a href="http://docs.oracle.com/javase/6/docs/technotes/guides/security/StandardNames.html">Java Cryptography
27+
* Architecture Standard Algorithm Name Documentation</a>
28+
* @since 1.7
29+
* @version $Id$
30+
*/
31+
public class MessageDigestAlgorithms {
32+
33+
/**
34+
* The MD2 message digest algorithm defined in RFC 1319.
35+
*/
36+
public static final String MD2 = "MD2";
37+
38+
/**
39+
* The MD5 message digest algorithm defined in RFC 1321.
40+
*/
41+
public static final String MD5 = "MD5";
42+
43+
/**
44+
* The SHA-1 hash algorithm defined in the FIPS PUB 180-2.
45+
*/
46+
public static final String SHA_1 = "SHA-1";
47+
48+
/**
49+
* The SHA-256 hash algorithm defined in the FIPS PUB 180-2.
50+
*/
51+
public static final String SHA_256 = "SHA-256";
52+
53+
/**
54+
* The SHA-384 hash algorithm defined in the FIPS PUB 180-2.
55+
*/
56+
public static final String SHA_384 = "SHA-384";
57+
58+
/**
59+
* The SHA-512 hash algorithm defined in the FIPS PUB 180-2.
60+
*/
61+
public static final String SHA_512 = "SHA-512";
62+
63+
}

0 commit comments

Comments
 (0)