FileDocCategorySizeDatePackage
SignatureAlgorithm.javaAPI DocJava SE 6 API13957Tue Jun 10 00:23:00 BST 2008com.sun.org.apache.xml.internal.security.algorithms

SignatureAlgorithm

public class SignatureAlgorithm extends Algorithm
Allows selection of digital signature's algorithm, private keys, other security parameters, and algorithm's ID.
author
Christian Geuer-Pollmann

Fields Summary
static Logger
log
{@link java.util.logging} logging facility
static boolean
_alreadyInitialized
Field _alreadyInitialized
static HashMap
_algorithmHash
All available algorithm classes are registered here
protected SignatureAlgorithmSpi
_signatureAlgorithm
Field _signatureAlgorithm
Constructors Summary
public SignatureAlgorithm(Document doc, String algorithmURI)
Constructor SignatureAlgorithm

param
doc
param
algorithmURI
throws
XMLSecurityException


               
       
             

      super(doc, algorithmURI);

      try {
         Class implementingClass =
            SignatureAlgorithm.getImplementingClass(algorithmURI);
         if (true)
         	if (log.isLoggable(java.util.logging.Level.FINE))                                     log.log(java.util.logging.Level.FINE, "Create URI \"" + algorithmURI + "\" class \""
                   + implementingClass + "\"");

         this._signatureAlgorithm =
            (SignatureAlgorithmSpi) implementingClass.newInstance();
      }  catch (IllegalAccessException ex) {
         Object exArgs[] = { algorithmURI, ex.getMessage() };

         throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs,
                                         ex);
      } catch (InstantiationException ex) {
         Object exArgs[] = { algorithmURI, ex.getMessage() };

         throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs,
                                         ex);
      } catch (NullPointerException ex) {
         Object exArgs[] = { algorithmURI, ex.getMessage() };

         throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs,
                                         ex);
      }
   
public SignatureAlgorithm(Document doc, String algorithmURI, int HMACOutputLength)
Constructor SignatureAlgorithm

param
doc
param
algorithmURI
param
HMACOutputLength
throws
XMLSecurityException


      this(doc, algorithmURI);

      this._signatureAlgorithm.engineSetHMACOutputLength(HMACOutputLength);
      ((IntegrityHmac)this._signatureAlgorithm)
         .engineAddContextToElement(this._constructionElement);
   
public SignatureAlgorithm(Element element, String BaseURI)
Constructor SignatureAlgorithm

param
element
param
BaseURI
throws
XMLSecurityException


      super(element, BaseURI);

      String algorithmURI = this.getURI();

      try {
         Class implementingClass =
            SignatureAlgorithm.getImplementingClass(algorithmURI);
         if (true)
         	if (log.isLoggable(java.util.logging.Level.FINE))                                     log.log(java.util.logging.Level.FINE, "Create URI \"" + algorithmURI + "\" class \""
                   + implementingClass + "\"");

         this._signatureAlgorithm =
            (SignatureAlgorithmSpi) implementingClass.newInstance();

         this._signatureAlgorithm
            .engineGetContextFromElement(this._constructionElement);
      }  catch (IllegalAccessException ex) {
         Object exArgs[] = { algorithmURI, ex.getMessage() };

         throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs,
                                         ex);
      } catch (InstantiationException ex) {
         Object exArgs[] = { algorithmURI, ex.getMessage() };

         throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs,
                                         ex);
      } catch (NullPointerException ex) {
         Object exArgs[] = { algorithmURI, ex.getMessage() };

         throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs,
                                         ex);
      }
   
Methods Summary
public java.lang.StringgetBaseLocalName()
Method getBaseLocalName

return
Local name

      return Constants._TAG_SIGNATUREMETHOD;
   
public java.lang.StringgetBaseNamespace()
Method getBaseNamespace

return
URI of this element

      return Constants.SignatureSpecNS;
   
private static java.lang.ClassgetImplementingClass(java.lang.String URI)
Method getImplementingClass

param
URI
return
the class that implements the URI


      if (SignatureAlgorithm._algorithmHash == null) {
         return null;
      }

      return (Class) SignatureAlgorithm._algorithmHash.get(URI);
   
public java.lang.StringgetJCEAlgorithmString()
Proxy method for {@link java.security.Signature#getAlgorithm} which is executed on the internal {@link java.security.Signature} object.

return
the result of the {@link java.security.Signature#getAlgorithm} method

      return this._signatureAlgorithm.engineGetJCEAlgorithmString();
   
public java.lang.StringgetJCEProviderName()
Method getJCEProviderName

return
The Provider of this Signature Alogrithm

      return this._signatureAlgorithm.engineGetJCEProviderName();
   
public final java.lang.StringgetURI()
Returns the URI representation of Transformation algorithm

return
the URI representation of Transformation algorithm

      return this._constructionElement.getAttributeNS(null,
              Constants._ATT_ALGORITHM);
   
public voidinitSign(java.security.Key signingKey)
Proxy method for {@link java.security.Signature#initSign(java.security.PrivateKey)} which is executed on the internal {@link java.security.Signature} object.

param
signingKey
throws
XMLSignatureException

      this._signatureAlgorithm.engineInitSign(signingKey);
   
public voidinitSign(java.security.Key signingKey, java.security.SecureRandom secureRandom)
Proxy method for {@link java.security.Signature#initSign(java.security.PrivateKey, java.security.SecureRandom)} which is executed on the internal {@link java.security.Signature} object.

param
signingKey
param
secureRandom
throws
XMLSignatureException

      this._signatureAlgorithm.engineInitSign(signingKey, secureRandom);
   
public voidinitSign(java.security.Key signingKey, java.security.spec.AlgorithmParameterSpec algorithmParameterSpec)
Proxy method for {@link java.security.Signature#initSign(java.security.PrivateKey)} which is executed on the internal {@link java.security.Signature} object.

param
signingKey
param
algorithmParameterSpec
throws
XMLSignatureException

      this._signatureAlgorithm.engineInitSign(signingKey,
                                              algorithmParameterSpec);
   
public voidinitVerify(java.security.Key verificationKey)
Proxy method for {@link java.security.Signature#initVerify(java.security.PublicKey)} which is executed on the internal {@link java.security.Signature} object.

param
verificationKey
throws
XMLSignatureException

      this._signatureAlgorithm.engineInitVerify(verificationKey);
   
public static voidproviderInit()
Initalizes for this {@link com.sun.org.apache.xml.internal.security.transforms.Transform}


      if (SignatureAlgorithm.log == null) {
         SignatureAlgorithm.log =
            java.util.logging.Logger
               .getLogger(SignatureAlgorithm.class.getName());
      }

      if (log.isLoggable(java.util.logging.Level.FINE))                                     log.log(java.util.logging.Level.FINE, "Init() called");

      if (!SignatureAlgorithm._alreadyInitialized) {
         SignatureAlgorithm._algorithmHash = new HashMap(10);
         SignatureAlgorithm._alreadyInitialized = true;
      }
   
public static voidregister(java.lang.String algorithmURI, java.lang.String implementingClass)
Registers implementing class of the Transform algorithm with algorithmURI

param
algorithmURI algorithmURI URI representation of Transform algorithm.
param
implementingClass implementingClass the implementing class of {@link SignatureAlgorithmSpi}
throws
AlgorithmAlreadyRegisteredException if specified algorithmURI is already registered
throws
XMLSignatureException


      {
         if (true)
         	if (log.isLoggable(java.util.logging.Level.FINE))                                     log.log(java.util.logging.Level.FINE, "Try to register " + algorithmURI + " " + implementingClass);

         // are we already registered?
         Class registeredClassClass =
            SignatureAlgorithm.getImplementingClass(algorithmURI);
		 if (registeredClassClass!=null) {
			 String registeredClass = registeredClassClass.getName();

			 if ((registeredClass != null) && (registeredClass.length() != 0)) {
				 Object exArgs[] = { algorithmURI, registeredClass };

				 throw new AlgorithmAlreadyRegisteredException(
						 "algorithm.alreadyRegistered", exArgs);
			 }
		 }
		 try {	         	   			 
			 SignatureAlgorithm._algorithmHash.put(algorithmURI, Class.forName(implementingClass));
	      } catch (ClassNotFoundException ex) {
	         Object exArgs[] = { algorithmURI, ex.getMessage() };

	         throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs,
	                                         ex);
	      } catch (NullPointerException ex) {
	         Object exArgs[] = { algorithmURI, ex.getMessage() };

	         throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs,
	                                         ex);
	      }
         
      }
   
public voidsetParameter(java.security.spec.AlgorithmParameterSpec params)
Proxy method for {@link java.security.Signature#setParameter(java.security.spec.AlgorithmParameterSpec)} which is executed on the internal {@link java.security.Signature} object.

param
params
throws
XMLSignatureException

      this._signatureAlgorithm.engineSetParameter(params);
   
public byte[]sign()
Proxy method for {@link java.security.Signature#sign()} which is executed on the internal {@link java.security.Signature} object.

return
the result of the {@link java.security.Signature#sign()} method
throws
XMLSignatureException

      return this._signatureAlgorithm.engineSign();
   
public voidupdate(byte[] input)
Proxy method for {@link java.security.Signature#update(byte[])} which is executed on the internal {@link java.security.Signature} object.

param
input
throws
XMLSignatureException

      this._signatureAlgorithm.engineUpdate(input);
   
public voidupdate(byte input)
Proxy method for {@link java.security.Signature#update(byte)} which is executed on the internal {@link java.security.Signature} object.

param
input
throws
XMLSignatureException

      this._signatureAlgorithm.engineUpdate(input);
   
public voidupdate(byte[] buf, int offset, int len)
Proxy method for {@link java.security.Signature#update(byte[], int, int)} which is executed on the internal {@link java.security.Signature} object.

param
buf
param
offset
param
len
throws
XMLSignatureException

      this._signatureAlgorithm.engineUpdate(buf, offset, len);
   
public booleanverify(byte[] signature)
Proxy method for {@link java.security.Signature#verify(byte[])} which is executed on the internal {@link java.security.Signature} object.

param
signature
return
true if if the signature is valid.
throws
XMLSignatureException

      return this._signatureAlgorithm.engineVerify(signature);