equal
deleted
inserted
replaced
32 import java.io.PrintStream; |
32 import java.io.PrintStream; |
33 import java.io.InputStream; |
33 import java.io.InputStream; |
34 import java.io.ByteArrayInputStream; |
34 import java.io.ByteArrayInputStream; |
35 |
35 |
36 import java.nio.ByteBuffer; |
36 import java.nio.ByteBuffer; |
|
37 |
|
38 import sun.security.util.Debug; |
37 |
39 |
38 /** |
40 /** |
39 * This MessageDigest class provides applications the functionality of a |
41 * This MessageDigest class provides applications the functionality of a |
40 * message digest algorithm, such as SHA-1 or SHA-256. |
42 * message digest algorithm, such as SHA-1 or SHA-256. |
41 * Message digests are secure one-way hash functions that take arbitrary-sized |
43 * Message digests are secure one-way hash functions that take arbitrary-sized |
101 * @see DigestOutputStream |
103 * @see DigestOutputStream |
102 */ |
104 */ |
103 |
105 |
104 public abstract class MessageDigest extends MessageDigestSpi { |
106 public abstract class MessageDigest extends MessageDigestSpi { |
105 |
107 |
|
108 private static final Debug pdebug = |
|
109 Debug.getInstance("provider", "Provider"); |
|
110 private static final boolean skipDebug = |
|
111 Debug.isOn("engine=") && !Debug.isOn("messagedigest"); |
|
112 |
106 private String algorithm; |
113 private String algorithm; |
107 |
114 |
108 // The state of this digest |
115 // The state of this digest |
109 private static final int INITIAL = 0; |
116 private static final int INITIAL = 0; |
110 private static final int IN_PROGRESS = 1; |
117 private static final int IN_PROGRESS = 1; |
154 * @see Provider |
161 * @see Provider |
155 */ |
162 */ |
156 public static MessageDigest getInstance(String algorithm) |
163 public static MessageDigest getInstance(String algorithm) |
157 throws NoSuchAlgorithmException { |
164 throws NoSuchAlgorithmException { |
158 try { |
165 try { |
|
166 MessageDigest md; |
159 Object[] objs = Security.getImpl(algorithm, "MessageDigest", |
167 Object[] objs = Security.getImpl(algorithm, "MessageDigest", |
160 (String)null); |
168 (String)null); |
161 if (objs[0] instanceof MessageDigest) { |
169 if (objs[0] instanceof MessageDigest) { |
162 MessageDigest md = (MessageDigest)objs[0]; |
170 md = (MessageDigest)objs[0]; |
163 md.provider = (Provider)objs[1]; |
|
164 return md; |
|
165 } else { |
171 } else { |
166 MessageDigest delegate = |
172 md = new Delegate((MessageDigestSpi)objs[0], algorithm); |
167 new Delegate((MessageDigestSpi)objs[0], algorithm); |
|
168 delegate.provider = (Provider)objs[1]; |
|
169 return delegate; |
|
170 } |
173 } |
|
174 md.provider = (Provider)objs[1]; |
|
175 |
|
176 if (!skipDebug && pdebug != null) { |
|
177 pdebug.println("MessageDigest." + algorithm + |
|
178 " algorithm from: " + md.provider.getName()); |
|
179 } |
|
180 |
|
181 return md; |
|
182 |
171 } catch(NoSuchProviderException e) { |
183 } catch(NoSuchProviderException e) { |
172 throw new NoSuchAlgorithmException(algorithm + " not found"); |
184 throw new NoSuchAlgorithmException(algorithm + " not found"); |
173 } |
185 } |
174 } |
186 } |
175 |
187 |