Integrate work by Raif S.
Integrate work by Raif S. Naffah (raif@fl.net.au)
* java/security/DummyKeyPairGenerator.java (clone): New method.
* java/security/DummyMessageDigest.java (clone): New method.
(engineUpdate): Now public.
(engineReset): Likewise.
(engineDigest): Likewise.
(engineGetDigestLength): New method.
* java/security/DummySignature.java (clone): New method.
* java/security/KeyPairGenerator.java (provider): Now package private.
(getInstance(String)): Use getInstance(String,Provider).
(getInstance(String,String): Use getInstance(String,Provider)
(getInstance(String,Provider): New method.
(getInstance(String,String,Provider): Don't cast DummyKeyPairGenerator.
* java/security/KeyPairGeneratorSpi.java (clone): New method.
* java/security/MessageDigest.java (provider): Now package private.
(getInstance(String): Use getInstance(String,Provider).
(getInstance(String,String): Use getInstance(String,Provider)
(getInstance(String,Provider): New method.
* java/security/Provider.java (toCanonicalKey): New method.
(get): New method that uses toCanonicalKey().
(put): Use toCanonicalKey().
(remove): Likewise.
* java/security/Security.java (insertProviderAt): Provider index is one
based, not zero based.
(addProvider): Likewise.
(removeProvider): Likewise.
* java/security/Signature.java (provider): Now package private.
(getInstance(String)): Use getInstance(String,Provider).
(getInstance(String,String): Use getInstance(String,Provider)
(getInstance(String,Provider): New method.
(getInstance(String,String,Provider): Don't cast DummySignature.
From-SVN: r59179
2002-11-17 08:10:24 +08:00
|
|
|
|
2001-04-25 23:45:15 +08:00
|
|
|
/* MessageDigest.java --- The message digest interface.
|
Integrate work by Raif S.
Integrate work by Raif S. Naffah (raif@fl.net.au)
* java/security/DummyKeyPairGenerator.java (clone): New method.
* java/security/DummyMessageDigest.java (clone): New method.
(engineUpdate): Now public.
(engineReset): Likewise.
(engineDigest): Likewise.
(engineGetDigestLength): New method.
* java/security/DummySignature.java (clone): New method.
* java/security/KeyPairGenerator.java (provider): Now package private.
(getInstance(String)): Use getInstance(String,Provider).
(getInstance(String,String): Use getInstance(String,Provider)
(getInstance(String,Provider): New method.
(getInstance(String,String,Provider): Don't cast DummyKeyPairGenerator.
* java/security/KeyPairGeneratorSpi.java (clone): New method.
* java/security/MessageDigest.java (provider): Now package private.
(getInstance(String): Use getInstance(String,Provider).
(getInstance(String,String): Use getInstance(String,Provider)
(getInstance(String,Provider): New method.
* java/security/Provider.java (toCanonicalKey): New method.
(get): New method that uses toCanonicalKey().
(put): Use toCanonicalKey().
(remove): Likewise.
* java/security/Security.java (insertProviderAt): Provider index is one
based, not zero based.
(addProvider): Likewise.
(removeProvider): Likewise.
* java/security/Signature.java (provider): Now package private.
(getInstance(String)): Use getInstance(String,Provider).
(getInstance(String,String): Use getInstance(String,Provider)
(getInstance(String,Provider): New method.
(getInstance(String,String,Provider): Don't cast DummySignature.
From-SVN: r59179
2002-11-17 08:10:24 +08:00
|
|
|
Copyright (C) 1999, 2002 Free Software Foundation, Inc.
|
1999-04-18 16:24:30 +08:00
|
|
|
|
2001-04-25 23:45:15 +08:00
|
|
|
This file is part of GNU Classpath.
|
1999-04-18 16:24:30 +08:00
|
|
|
|
2001-04-25 23:45:15 +08:00
|
|
|
GNU Classpath is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
any later version.
|
1999-04-18 16:24:30 +08:00
|
|
|
|
2001-04-25 23:45:15 +08:00
|
|
|
GNU Classpath is distributed in the hope that it will be useful, but
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
General Public License for more details.
|
1999-04-18 16:24:30 +08:00
|
|
|
|
2001-04-25 23:45:15 +08:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with GNU Classpath; see the file COPYING. If not, write to the
|
|
|
|
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
|
|
|
02111-1307 USA.
|
1999-04-18 16:24:30 +08:00
|
|
|
|
2002-01-23 06:40:42 +08:00
|
|
|
Linking this library statically or dynamically with other modules is
|
|
|
|
making a combined work based on this library. Thus, the terms and
|
|
|
|
conditions of the GNU General Public License cover the whole
|
|
|
|
combination.
|
|
|
|
|
|
|
|
As a special exception, the copyright holders of this library give you
|
|
|
|
permission to link this library with independent modules to produce an
|
|
|
|
executable, regardless of the license terms of these independent
|
|
|
|
modules, and to copy and distribute the resulting executable under
|
|
|
|
terms of your choice, provided that you also meet, for each linked
|
|
|
|
independent module, the terms and conditions of the license of that
|
|
|
|
module. An independent module is a module which is not derived from
|
|
|
|
or based on this library. If you modify this library, you may extend
|
|
|
|
this exception to your version of the library, but you are not
|
|
|
|
obligated to do so. If you do not wish to do so, delete this
|
|
|
|
exception statement from your version. */
|
2000-03-10 10:43:57 +08:00
|
|
|
|
2001-04-25 23:45:15 +08:00
|
|
|
package java.security;
|
2000-03-10 10:43:57 +08:00
|
|
|
|
2001-04-25 23:45:15 +08:00
|
|
|
public abstract class MessageDigest extends MessageDigestSpi
|
1999-04-18 16:24:30 +08:00
|
|
|
{
|
2001-04-25 23:45:15 +08:00
|
|
|
private String algorithm;
|
Integrate work by Raif S.
Integrate work by Raif S. Naffah (raif@fl.net.au)
* java/security/DummyKeyPairGenerator.java (clone): New method.
* java/security/DummyMessageDigest.java (clone): New method.
(engineUpdate): Now public.
(engineReset): Likewise.
(engineDigest): Likewise.
(engineGetDigestLength): New method.
* java/security/DummySignature.java (clone): New method.
* java/security/KeyPairGenerator.java (provider): Now package private.
(getInstance(String)): Use getInstance(String,Provider).
(getInstance(String,String): Use getInstance(String,Provider)
(getInstance(String,Provider): New method.
(getInstance(String,String,Provider): Don't cast DummyKeyPairGenerator.
* java/security/KeyPairGeneratorSpi.java (clone): New method.
* java/security/MessageDigest.java (provider): Now package private.
(getInstance(String): Use getInstance(String,Provider).
(getInstance(String,String): Use getInstance(String,Provider)
(getInstance(String,Provider): New method.
* java/security/Provider.java (toCanonicalKey): New method.
(get): New method that uses toCanonicalKey().
(put): Use toCanonicalKey().
(remove): Likewise.
* java/security/Security.java (insertProviderAt): Provider index is one
based, not zero based.
(addProvider): Likewise.
(removeProvider): Likewise.
* java/security/Signature.java (provider): Now package private.
(getInstance(String)): Use getInstance(String,Provider).
(getInstance(String,String): Use getInstance(String,Provider)
(getInstance(String,Provider): New method.
(getInstance(String,String,Provider): Don't cast DummySignature.
From-SVN: r59179
2002-11-17 08:10:24 +08:00
|
|
|
Provider provider;
|
2001-04-25 23:45:15 +08:00
|
|
|
private byte[] lastDigest;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Creates a MessageDigest representing the specified
|
|
|
|
algorithm.
|
|
|
|
|
|
|
|
@param algorithm the name of digest algorithm to choose
|
|
|
|
*/
|
|
|
|
protected MessageDigest(String algorithm)
|
2000-03-10 10:43:57 +08:00
|
|
|
{
|
2001-04-25 23:45:15 +08:00
|
|
|
this.algorithm = algorithm;
|
|
|
|
provider = null;
|
2000-03-10 10:43:57 +08:00
|
|
|
}
|
|
|
|
|
2001-04-25 23:45:15 +08:00
|
|
|
/**
|
|
|
|
Gets an instance of the MessageDigest class representing
|
|
|
|
the specified digest. If the algorithm is not found then,
|
|
|
|
it throws NoSuchAlgorithmException.
|
|
|
|
|
|
|
|
@param algorithm the name of digest algorithm to choose
|
|
|
|
@return a MessageDigest representing the desired algorithm
|
|
|
|
|
Integrate work by Raif S.
Integrate work by Raif S. Naffah (raif@fl.net.au)
* java/security/DummyKeyPairGenerator.java (clone): New method.
* java/security/DummyMessageDigest.java (clone): New method.
(engineUpdate): Now public.
(engineReset): Likewise.
(engineDigest): Likewise.
(engineGetDigestLength): New method.
* java/security/DummySignature.java (clone): New method.
* java/security/KeyPairGenerator.java (provider): Now package private.
(getInstance(String)): Use getInstance(String,Provider).
(getInstance(String,String): Use getInstance(String,Provider)
(getInstance(String,Provider): New method.
(getInstance(String,String,Provider): Don't cast DummyKeyPairGenerator.
* java/security/KeyPairGeneratorSpi.java (clone): New method.
* java/security/MessageDigest.java (provider): Now package private.
(getInstance(String): Use getInstance(String,Provider).
(getInstance(String,String): Use getInstance(String,Provider)
(getInstance(String,Provider): New method.
* java/security/Provider.java (toCanonicalKey): New method.
(get): New method that uses toCanonicalKey().
(put): Use toCanonicalKey().
(remove): Likewise.
* java/security/Security.java (insertProviderAt): Provider index is one
based, not zero based.
(addProvider): Likewise.
(removeProvider): Likewise.
* java/security/Signature.java (provider): Now package private.
(getInstance(String)): Use getInstance(String,Provider).
(getInstance(String,String): Use getInstance(String,Provider)
(getInstance(String,Provider): New method.
(getInstance(String,String,Provider): Don't cast DummySignature.
From-SVN: r59179
2002-11-17 08:10:24 +08:00
|
|
|
@exception NoSuchAlgorithmException if the algorithm is not implemented by
|
|
|
|
providers
|
2001-04-25 23:45:15 +08:00
|
|
|
*/
|
|
|
|
public static MessageDigest getInstance(String algorithm)
|
2000-03-10 10:43:57 +08:00
|
|
|
throws NoSuchAlgorithmException
|
|
|
|
{
|
2001-04-25 23:45:15 +08:00
|
|
|
Provider[] p = Security.getProviders();
|
|
|
|
for (int i = 0; i < p.length; i++)
|
2000-03-10 10:43:57 +08:00
|
|
|
{
|
Integrate work by Raif S.
Integrate work by Raif S. Naffah (raif@fl.net.au)
* java/security/DummyKeyPairGenerator.java (clone): New method.
* java/security/DummyMessageDigest.java (clone): New method.
(engineUpdate): Now public.
(engineReset): Likewise.
(engineDigest): Likewise.
(engineGetDigestLength): New method.
* java/security/DummySignature.java (clone): New method.
* java/security/KeyPairGenerator.java (provider): Now package private.
(getInstance(String)): Use getInstance(String,Provider).
(getInstance(String,String): Use getInstance(String,Provider)
(getInstance(String,Provider): New method.
(getInstance(String,String,Provider): Don't cast DummyKeyPairGenerator.
* java/security/KeyPairGeneratorSpi.java (clone): New method.
* java/security/MessageDigest.java (provider): Now package private.
(getInstance(String): Use getInstance(String,Provider).
(getInstance(String,String): Use getInstance(String,Provider)
(getInstance(String,Provider): New method.
* java/security/Provider.java (toCanonicalKey): New method.
(get): New method that uses toCanonicalKey().
(put): Use toCanonicalKey().
(remove): Likewise.
* java/security/Security.java (insertProviderAt): Provider index is one
based, not zero based.
(addProvider): Likewise.
(removeProvider): Likewise.
* java/security/Signature.java (provider): Now package private.
(getInstance(String)): Use getInstance(String,Provider).
(getInstance(String,String): Use getInstance(String,Provider)
(getInstance(String,Provider): New method.
(getInstance(String,String,Provider): Don't cast DummySignature.
From-SVN: r59179
2002-11-17 08:10:24 +08:00
|
|
|
try
|
|
|
|
{
|
|
|
|
return getInstance(algorithm, p[i]);
|
|
|
|
}
|
|
|
|
catch (NoSuchAlgorithmException ignored) {}
|
2000-03-10 10:43:57 +08:00
|
|
|
}
|
|
|
|
|
2001-04-25 23:45:15 +08:00
|
|
|
throw new NoSuchAlgorithmException(algorithm);
|
2000-03-10 10:43:57 +08:00
|
|
|
}
|
|
|
|
|
2001-04-25 23:45:15 +08:00
|
|
|
/**
|
|
|
|
Gets an instance of the MessageDigest class representing
|
|
|
|
the specified digest from the specified provider. If the
|
|
|
|
algorithm is not found then, it throws NoSuchAlgorithmException.
|
|
|
|
If the provider is not found, then it throws
|
|
|
|
NoSuchProviderException.
|
|
|
|
|
|
|
|
@param algorithm the name of digest algorithm to choose
|
|
|
|
@param provider the name of the provider to find the algorithm in
|
|
|
|
@return a MessageDigest representing the desired algorithm
|
|
|
|
|
Integrate work by Raif S.
Integrate work by Raif S. Naffah (raif@fl.net.au)
* java/security/DummyKeyPairGenerator.java (clone): New method.
* java/security/DummyMessageDigest.java (clone): New method.
(engineUpdate): Now public.
(engineReset): Likewise.
(engineDigest): Likewise.
(engineGetDigestLength): New method.
* java/security/DummySignature.java (clone): New method.
* java/security/KeyPairGenerator.java (provider): Now package private.
(getInstance(String)): Use getInstance(String,Provider).
(getInstance(String,String): Use getInstance(String,Provider)
(getInstance(String,Provider): New method.
(getInstance(String,String,Provider): Don't cast DummyKeyPairGenerator.
* java/security/KeyPairGeneratorSpi.java (clone): New method.
* java/security/MessageDigest.java (provider): Now package private.
(getInstance(String): Use getInstance(String,Provider).
(getInstance(String,String): Use getInstance(String,Provider)
(getInstance(String,Provider): New method.
* java/security/Provider.java (toCanonicalKey): New method.
(get): New method that uses toCanonicalKey().
(put): Use toCanonicalKey().
(remove): Likewise.
* java/security/Security.java (insertProviderAt): Provider index is one
based, not zero based.
(addProvider): Likewise.
(removeProvider): Likewise.
* java/security/Signature.java (provider): Now package private.
(getInstance(String)): Use getInstance(String,Provider).
(getInstance(String,String): Use getInstance(String,Provider)
(getInstance(String,Provider): New method.
(getInstance(String,String,Provider): Don't cast DummySignature.
From-SVN: r59179
2002-11-17 08:10:24 +08:00
|
|
|
@exception NoSuchAlgorithmException if the algorithm is not implemented by
|
|
|
|
the provider
|
2001-04-25 23:45:15 +08:00
|
|
|
@exception NoSuchProviderException if the provider is not found
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static MessageDigest getInstance(String algorithm, String provider)
|
2000-03-10 10:43:57 +08:00
|
|
|
throws NoSuchAlgorithmException, NoSuchProviderException
|
|
|
|
{
|
2001-04-25 23:45:15 +08:00
|
|
|
Provider p = Security.getProvider(provider);
|
|
|
|
|
2000-03-10 10:43:57 +08:00
|
|
|
if (p == null)
|
2001-04-25 23:45:15 +08:00
|
|
|
throw new NoSuchProviderException(provider);
|
|
|
|
|
Integrate work by Raif S.
Integrate work by Raif S. Naffah (raif@fl.net.au)
* java/security/DummyKeyPairGenerator.java (clone): New method.
* java/security/DummyMessageDigest.java (clone): New method.
(engineUpdate): Now public.
(engineReset): Likewise.
(engineDigest): Likewise.
(engineGetDigestLength): New method.
* java/security/DummySignature.java (clone): New method.
* java/security/KeyPairGenerator.java (provider): Now package private.
(getInstance(String)): Use getInstance(String,Provider).
(getInstance(String,String): Use getInstance(String,Provider)
(getInstance(String,Provider): New method.
(getInstance(String,String,Provider): Don't cast DummyKeyPairGenerator.
* java/security/KeyPairGeneratorSpi.java (clone): New method.
* java/security/MessageDigest.java (provider): Now package private.
(getInstance(String): Use getInstance(String,Provider).
(getInstance(String,String): Use getInstance(String,Provider)
(getInstance(String,Provider): New method.
* java/security/Provider.java (toCanonicalKey): New method.
(get): New method that uses toCanonicalKey().
(put): Use toCanonicalKey().
(remove): Likewise.
* java/security/Security.java (insertProviderAt): Provider index is one
based, not zero based.
(addProvider): Likewise.
(removeProvider): Likewise.
* java/security/Signature.java (provider): Now package private.
(getInstance(String)): Use getInstance(String,Provider).
(getInstance(String,String): Use getInstance(String,Provider)
(getInstance(String,Provider): New method.
(getInstance(String,String,Provider): Don't cast DummySignature.
From-SVN: r59179
2002-11-17 08:10:24 +08:00
|
|
|
return getInstance(algorithm, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static MessageDigest getInstance(String algorithm, Provider p)
|
|
|
|
throws NoSuchAlgorithmException
|
|
|
|
{
|
|
|
|
// try the name as is
|
|
|
|
String className = p.getProperty("MessageDigest." + algorithm);
|
|
|
|
if (className == null) { // try all uppercase
|
|
|
|
String upper = algorithm.toUpperCase();
|
|
|
|
className = p.getProperty("MessageDigest." + upper);
|
|
|
|
if (className == null) { // try if it's an alias
|
|
|
|
String alias = p.getProperty("Alg.Alias.MessageDigest." +algorithm);
|
|
|
|
if (alias == null) { // try all-uppercase alias name
|
|
|
|
alias = p.getProperty("Alg.Alias.MessageDigest." +upper);
|
|
|
|
if (alias == null) { // spit the dummy
|
|
|
|
throw new NoSuchAlgorithmException(algorithm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
className = p.getProperty("MessageDigest." + alias);
|
|
|
|
if (className == null) {
|
|
|
|
throw new NoSuchAlgorithmException(algorithm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return getInstance(className, algorithm, p);
|
2001-04-25 23:45:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private static MessageDigest getInstance(String classname,
|
|
|
|
String algorithm,
|
|
|
|
Provider provider)
|
|
|
|
throws NoSuchAlgorithmException
|
|
|
|
{
|
|
|
|
if (classname == null)
|
|
|
|
throw new NoSuchAlgorithmException(algorithm);
|
|
|
|
|
Integrate work by Raif S.
Integrate work by Raif S. Naffah (raif@fl.net.au)
* java/security/DummyKeyPairGenerator.java (clone): New method.
* java/security/DummyMessageDigest.java (clone): New method.
(engineUpdate): Now public.
(engineReset): Likewise.
(engineDigest): Likewise.
(engineGetDigestLength): New method.
* java/security/DummySignature.java (clone): New method.
* java/security/KeyPairGenerator.java (provider): Now package private.
(getInstance(String)): Use getInstance(String,Provider).
(getInstance(String,String): Use getInstance(String,Provider)
(getInstance(String,Provider): New method.
(getInstance(String,String,Provider): Don't cast DummyKeyPairGenerator.
* java/security/KeyPairGeneratorSpi.java (clone): New method.
* java/security/MessageDigest.java (provider): Now package private.
(getInstance(String): Use getInstance(String,Provider).
(getInstance(String,String): Use getInstance(String,Provider)
(getInstance(String,Provider): New method.
* java/security/Provider.java (toCanonicalKey): New method.
(get): New method that uses toCanonicalKey().
(put): Use toCanonicalKey().
(remove): Likewise.
* java/security/Security.java (insertProviderAt): Provider index is one
based, not zero based.
(addProvider): Likewise.
(removeProvider): Likewise.
* java/security/Signature.java (provider): Now package private.
(getInstance(String)): Use getInstance(String,Provider).
(getInstance(String,String): Use getInstance(String,Provider)
(getInstance(String,Provider): New method.
(getInstance(String,String,Provider): Don't cast DummySignature.
From-SVN: r59179
2002-11-17 08:10:24 +08:00
|
|
|
MessageDigest result = null;
|
2001-04-25 23:45:15 +08:00
|
|
|
try
|
|
|
|
{
|
Integrate work by Raif S.
Integrate work by Raif S. Naffah (raif@fl.net.au)
* java/security/DummyKeyPairGenerator.java (clone): New method.
* java/security/DummyMessageDigest.java (clone): New method.
(engineUpdate): Now public.
(engineReset): Likewise.
(engineDigest): Likewise.
(engineGetDigestLength): New method.
* java/security/DummySignature.java (clone): New method.
* java/security/KeyPairGenerator.java (provider): Now package private.
(getInstance(String)): Use getInstance(String,Provider).
(getInstance(String,String): Use getInstance(String,Provider)
(getInstance(String,Provider): New method.
(getInstance(String,String,Provider): Don't cast DummyKeyPairGenerator.
* java/security/KeyPairGeneratorSpi.java (clone): New method.
* java/security/MessageDigest.java (provider): Now package private.
(getInstance(String): Use getInstance(String,Provider).
(getInstance(String,String): Use getInstance(String,Provider)
(getInstance(String,Provider): New method.
* java/security/Provider.java (toCanonicalKey): New method.
(get): New method that uses toCanonicalKey().
(put): Use toCanonicalKey().
(remove): Likewise.
* java/security/Security.java (insertProviderAt): Provider index is one
based, not zero based.
(addProvider): Likewise.
(removeProvider): Likewise.
* java/security/Signature.java (provider): Now package private.
(getInstance(String)): Use getInstance(String,Provider).
(getInstance(String,String): Use getInstance(String,Provider)
(getInstance(String,Provider): New method.
(getInstance(String,String,Provider): Don't cast DummySignature.
From-SVN: r59179
2002-11-17 08:10:24 +08:00
|
|
|
Object obj = Class.forName(classname).newInstance();
|
|
|
|
if (obj instanceof MessageDigest) {
|
|
|
|
result = (MessageDigest) obj;
|
|
|
|
result.algorithm = algorithm;
|
|
|
|
} else if (obj instanceof MessageDigestSpi) {
|
|
|
|
result = new DummyMessageDigest((MessageDigestSpi) obj, algorithm);
|
|
|
|
} else {
|
|
|
|
throw new ClassCastException("Class "+classname+" from Provider "
|
|
|
|
+provider.getName()
|
|
|
|
+" does not extend java.security.MessageDigestSpi");
|
|
|
|
}
|
|
|
|
result.provider = provider;
|
|
|
|
return result;
|
2001-04-25 23:45:15 +08:00
|
|
|
}
|
|
|
|
catch (ClassNotFoundException cnfe)
|
|
|
|
{
|
|
|
|
throw new NoSuchAlgorithmException(algorithm + ": Class not found.");
|
|
|
|
}
|
|
|
|
catch (InstantiationException ie)
|
2000-03-10 10:43:57 +08:00
|
|
|
{
|
2001-04-25 23:45:15 +08:00
|
|
|
throw new NoSuchAlgorithmException(algorithm
|
|
|
|
+ ": Class instantiation failed.");
|
2000-03-10 10:43:57 +08:00
|
|
|
}
|
2001-04-25 23:45:15 +08:00
|
|
|
catch (IllegalAccessException iae)
|
|
|
|
{
|
|
|
|
throw new NoSuchAlgorithmException(algorithm + ": Illegal Access");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-03-10 10:43:57 +08:00
|
|
|
|
2001-04-25 23:45:15 +08:00
|
|
|
/**
|
|
|
|
Gets the provider that the MessageDigest is from.
|
|
|
|
|
|
|
|
@return the provider the this MessageDigest
|
|
|
|
*/
|
|
|
|
public final Provider getProvider()
|
|
|
|
{
|
|
|
|
return provider;
|
2000-03-10 10:43:57 +08:00
|
|
|
}
|
|
|
|
|
2001-04-25 23:45:15 +08:00
|
|
|
/**
|
|
|
|
Updates the digest with the byte.
|
|
|
|
|
|
|
|
@param input byte to update the digest with
|
|
|
|
*/
|
|
|
|
public void update(byte input)
|
2000-03-10 10:43:57 +08:00
|
|
|
{
|
2001-04-25 23:45:15 +08:00
|
|
|
engineUpdate(input);
|
2000-03-10 10:43:57 +08:00
|
|
|
}
|
|
|
|
|
2001-04-25 23:45:15 +08:00
|
|
|
/**
|
|
|
|
Updates the digest with the bytes from the array from the
|
|
|
|
specified offset to the specified length.
|
|
|
|
|
|
|
|
@param input bytes to update the digest with
|
|
|
|
@param offset the offset to start at
|
|
|
|
@param len length of the data to update with
|
|
|
|
*/
|
|
|
|
public void update(byte[]input, int offset, int len)
|
2000-03-10 10:43:57 +08:00
|
|
|
{
|
2002-05-24 19:57:40 +08:00
|
|
|
engineUpdate(input, offset, len);
|
2000-03-10 10:43:57 +08:00
|
|
|
}
|
|
|
|
|
2001-04-25 23:45:15 +08:00
|
|
|
/**
|
|
|
|
Updates the digest with the bytes from the array.
|
|
|
|
|
|
|
|
@param input bytes to update the digest with
|
|
|
|
*/
|
|
|
|
public void update(byte[]input)
|
2000-03-10 10:43:57 +08:00
|
|
|
{
|
2001-04-25 23:45:15 +08:00
|
|
|
engineUpdate(input, 0, input.length);
|
2000-03-10 10:43:57 +08:00
|
|
|
}
|
|
|
|
|
2001-04-25 23:45:15 +08:00
|
|
|
/**
|
|
|
|
Computes the digest of the stored data.
|
|
|
|
|
|
|
|
@return a byte array representing the message digest
|
|
|
|
*/
|
|
|
|
public byte[] digest()
|
|
|
|
{
|
|
|
|
return lastDigest = engineDigest();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Computes the final digest of the stored bytes and returns
|
|
|
|
them.
|
|
|
|
|
|
|
|
@param buf An array of bytes to store the digest
|
|
|
|
@param offset An offset to start storing the digest at
|
|
|
|
@param len The length of the buffer
|
|
|
|
@return Returns the length of the buffer
|
|
|
|
*/
|
|
|
|
public int digest(byte[]buf, int offset, int len) throws DigestException
|
2000-03-10 10:43:57 +08:00
|
|
|
{
|
2001-04-25 23:45:15 +08:00
|
|
|
return engineDigest(buf, offset, len);
|
2000-03-10 10:43:57 +08:00
|
|
|
}
|
|
|
|
|
2001-04-25 23:45:15 +08:00
|
|
|
/**
|
|
|
|
Computes a final update using the input array of bytes,
|
|
|
|
then computes a final digest and returns it. It calls
|
|
|
|
update(input) and then digest();
|
|
|
|
|
Integrate work by Raif S.
Integrate work by Raif S. Naffah (raif@fl.net.au)
* java/security/DummyKeyPairGenerator.java (clone): New method.
* java/security/DummyMessageDigest.java (clone): New method.
(engineUpdate): Now public.
(engineReset): Likewise.
(engineDigest): Likewise.
(engineGetDigestLength): New method.
* java/security/DummySignature.java (clone): New method.
* java/security/KeyPairGenerator.java (provider): Now package private.
(getInstance(String)): Use getInstance(String,Provider).
(getInstance(String,String): Use getInstance(String,Provider)
(getInstance(String,Provider): New method.
(getInstance(String,String,Provider): Don't cast DummyKeyPairGenerator.
* java/security/KeyPairGeneratorSpi.java (clone): New method.
* java/security/MessageDigest.java (provider): Now package private.
(getInstance(String): Use getInstance(String,Provider).
(getInstance(String,String): Use getInstance(String,Provider)
(getInstance(String,Provider): New method.
* java/security/Provider.java (toCanonicalKey): New method.
(get): New method that uses toCanonicalKey().
(put): Use toCanonicalKey().
(remove): Likewise.
* java/security/Security.java (insertProviderAt): Provider index is one
based, not zero based.
(addProvider): Likewise.
(removeProvider): Likewise.
* java/security/Signature.java (provider): Now package private.
(getInstance(String)): Use getInstance(String,Provider).
(getInstance(String,String): Use getInstance(String,Provider)
(getInstance(String,Provider): New method.
(getInstance(String,String,Provider): Don't cast DummySignature.
From-SVN: r59179
2002-11-17 08:10:24 +08:00
|
|
|
@param input An array of bytes to perform final update with
|
2001-04-25 23:45:15 +08:00
|
|
|
@return a byte array representing the message digest
|
|
|
|
*/
|
|
|
|
public byte[] digest(byte[]input)
|
2000-03-10 10:43:57 +08:00
|
|
|
{
|
2001-04-25 23:45:15 +08:00
|
|
|
update(input);
|
|
|
|
return digest();
|
2000-03-10 10:43:57 +08:00
|
|
|
}
|
|
|
|
|
2001-04-25 23:45:15 +08:00
|
|
|
/**
|
|
|
|
Returns a representation of the MessageDigest as a String.
|
|
|
|
|
|
|
|
@return a string representing the message digest
|
|
|
|
*/
|
|
|
|
public String toString()
|
2000-03-10 10:43:57 +08:00
|
|
|
{
|
2001-04-25 23:45:15 +08:00
|
|
|
return (getClass()).getName()
|
|
|
|
+ " Message Digest <" + digestToString() + ">";
|
2000-03-10 10:43:57 +08:00
|
|
|
}
|
|
|
|
|
2001-04-25 23:45:15 +08:00
|
|
|
/**
|
|
|
|
Does a simple byte comparison of the two digests.
|
|
|
|
|
|
|
|
@param digesta first digest to compare
|
|
|
|
@param digestb second digest to compare
|
|
|
|
@return true if they are equal, false otherwise
|
|
|
|
*/
|
|
|
|
public static boolean isEqual(byte[]digesta, byte[]digestb)
|
2000-03-10 10:43:57 +08:00
|
|
|
{
|
|
|
|
if (digesta.length != digestb.length)
|
|
|
|
return false;
|
2001-04-25 23:45:15 +08:00
|
|
|
|
2000-03-10 10:43:57 +08:00
|
|
|
for (int i = digesta.length - 1; i >= 0; --i)
|
|
|
|
if (digesta[i] != digestb[i])
|
|
|
|
return false;
|
2001-04-25 23:45:15 +08:00
|
|
|
|
2000-03-10 10:43:57 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2001-04-25 23:45:15 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
Resets the message digest.
|
|
|
|
*/
|
|
|
|
public void reset()
|
|
|
|
{
|
|
|
|
engineReset();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Gets the name of the algorithm currently used.
|
|
|
|
The names of algorithms are usually SHA-1 or MD5.
|
|
|
|
|
|
|
|
@return name of algorithm.
|
|
|
|
*/
|
|
|
|
public final String getAlgorithm()
|
2000-03-10 10:43:57 +08:00
|
|
|
{
|
2001-04-25 23:45:15 +08:00
|
|
|
return algorithm;
|
2000-03-10 10:43:57 +08:00
|
|
|
}
|
|
|
|
|
2001-04-25 23:45:15 +08:00
|
|
|
/**
|
|
|
|
Gets the length of the message digest.
|
|
|
|
The default is zero which means that this message digest
|
|
|
|
does not implement this function.
|
|
|
|
|
|
|
|
@return length of the message digest
|
|
|
|
*/
|
|
|
|
public final int getDigestLength()
|
2000-03-10 10:43:57 +08:00
|
|
|
{
|
2001-04-25 23:45:15 +08:00
|
|
|
return engineGetDigestLength();
|
2000-03-10 10:43:57 +08:00
|
|
|
}
|
|
|
|
|
2001-04-25 23:45:15 +08:00
|
|
|
/**
|
|
|
|
Returns a clone of this class if supported.
|
|
|
|
If it does not then it throws CloneNotSupportedException.
|
|
|
|
The cloning of this class depends on whether the subclass
|
|
|
|
MessageDigestSpi implements Cloneable which contains the
|
|
|
|
actual implementation of the appropriate algorithm.
|
2000-03-10 10:43:57 +08:00
|
|
|
|
2001-04-25 23:45:15 +08:00
|
|
|
@return clone of this class
|
|
|
|
|
|
|
|
@exception CloneNotSupportedException this class does not support cloning
|
|
|
|
*/
|
2000-03-10 10:43:57 +08:00
|
|
|
public Object clone() throws CloneNotSupportedException
|
|
|
|
{
|
2001-04-25 23:45:15 +08:00
|
|
|
if (this instanceof Cloneable)
|
|
|
|
return super.clone();
|
|
|
|
else
|
|
|
|
throw new CloneNotSupportedException();
|
|
|
|
}
|
|
|
|
|
|
|
|
private String digestToString()
|
|
|
|
{
|
|
|
|
byte[] digest = lastDigest;
|
|
|
|
|
|
|
|
if (digest == null)
|
|
|
|
return "incomplete";
|
|
|
|
|
|
|
|
StringBuffer buf = new StringBuffer();
|
|
|
|
int len = digest.length;
|
|
|
|
for (int i = 0; i < len; ++i)
|
|
|
|
{
|
|
|
|
byte b = digest[i];
|
|
|
|
byte high = (byte) ((b & 0xff) >>> 4);
|
|
|
|
byte low = (byte) (b & 0xf);
|
|
|
|
|
|
|
|
buf.append(high > 9 ? ('a' - 10) + high : '0' + high);
|
|
|
|
buf.append(low > 9 ? ('a' - 10) + low : '0' + low);
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf.toString();
|
2000-03-10 10:43:57 +08:00
|
|
|
}
|
|
|
|
|
1999-04-18 16:24:30 +08:00
|
|
|
}
|