1 4 7 package javax.xml.crypto.dsig; 8 9 import javax.xml.crypto.Data; 10 import javax.xml.crypto.MarshalException; 11 import javax.xml.crypto.NoSuchMechanismException; 12 import javax.xml.crypto.URIDereferencer; 13 import javax.xml.crypto.XMLStructure; 14 import javax.xml.crypto.dom.DOMStructure; 15 import javax.xml.crypto.dsig.keyinfo.KeyInfo; 16 import javax.xml.crypto.dsig.keyinfo.KeyInfoFactory; 17 import javax.xml.crypto.dsig.spec.*; 18 import javax.xml.crypto.dsig.dom.DOMValidateContext; 19 import javax.xml.crypto.dsig.dom.DOMSignContext; 20 21 import java.security.InvalidAlgorithmParameterException ; 22 import java.security.NoSuchAlgorithmException ; 23 import java.security.NoSuchProviderException ; 24 import java.security.Provider ; 25 import java.security.Security ; 26 import java.util.List ; 27 28 import sun.security.jca.*; 29 import sun.security.jca.GetInstance.Instance; 30 31 130 public abstract class XMLSignatureFactory { 131 132 private String mechanismType; 133 private Provider provider; 134 135 138 protected XMLSignatureFactory() {} 139 140 168 public static XMLSignatureFactory getInstance(String mechanismType) { 169 if (mechanismType == null) { 170 throw new NullPointerException ("mechanismType cannot be null"); 171 } 172 Instance instance; 173 try { 174 instance = GetInstance.getInstance 175 ("XMLSignatureFactory", null, mechanismType); 176 } catch (NoSuchAlgorithmException nsae) { 177 throw new NoSuchMechanismException(nsae); 178 } 179 XMLSignatureFactory factory = (XMLSignatureFactory) instance.impl; 180 factory.mechanismType = mechanismType; 181 factory.provider = instance.provider; 182 return factory; 183 } 184 185 206 public static XMLSignatureFactory getInstance(String mechanismType, 207 Provider provider) { 208 if (mechanismType == null) { 209 throw new NullPointerException ("mechanismType cannot be null"); 210 } else if (provider == null) { 211 throw new NullPointerException ("provider cannot be null"); 212 } 213 214 Instance instance; 215 try { 216 instance = GetInstance.getInstance 217 ("XMLSignatureFactory", null, mechanismType, provider); 218 } catch (NoSuchAlgorithmException nsae) { 219 throw new NoSuchMechanismException(nsae); 220 } 221 XMLSignatureFactory factory = (XMLSignatureFactory) instance.impl; 222 factory.mechanismType = mechanismType; 223 factory.provider = instance.provider; 224 return factory; 225 } 226 227 252 public static XMLSignatureFactory getInstance(String mechanismType, 253 String provider) throws NoSuchProviderException { 254 if (mechanismType == null) { 255 throw new NullPointerException ("mechanismType cannot be null"); 256 } else if (provider == null) { 257 throw new NullPointerException ("provider cannot be null"); 258 } else if (provider.length() == 0) { 259 throw new NoSuchProviderException (); 260 } 261 262 Instance instance; 263 try { 264 instance = GetInstance.getInstance 265 ("XMLSignatureFactory", null, mechanismType, provider); 266 } catch (NoSuchAlgorithmException nsae) { 267 throw new NoSuchMechanismException(nsae); 268 } 269 XMLSignatureFactory factory = (XMLSignatureFactory) instance.impl; 270 factory.mechanismType = mechanismType; 271 factory.provider = instance.provider; 272 return factory; 273 } 274 275 296 public static XMLSignatureFactory getInstance() { 297 return getInstance("DOM"); 298 } 299 300 307 public final String getMechanismType() { 308 return mechanismType; 309 } 310 311 316 public final Provider getProvider() { 317 return provider; 318 } 319 320 330 public abstract XMLSignature newXMLSignature(SignedInfo si, KeyInfo ki); 331 332 347 public abstract XMLSignature newXMLSignature(SignedInfo si, KeyInfo ki, 348 List objects, String id, String signatureValueId); 349 350 361 public abstract Reference newReference(String uri, DigestMethod dm); 362 363 380 public abstract Reference newReference(String uri, DigestMethod dm, 381 List transforms, String type, String id); 382 383 410 public abstract Reference newReference(String uri, DigestMethod dm, 411 List transforms, String type, String id, byte[] digestValue); 412 413 452 public abstract Reference newReference(String uri, DigestMethod dm, 453 List appliedTransforms, Data result, List transforms, String type, 454 String id); 455 456 471 public abstract SignedInfo newSignedInfo(CanonicalizationMethod cm, 472 SignatureMethod sm, List references); 473 474 489 public abstract SignedInfo newSignedInfo(CanonicalizationMethod cm, 490 SignatureMethod sm, List references, String id); 491 492 506 public abstract XMLObject newXMLObject(List content, String id, 507 String mimeType, String encoding); 508 509 522 public abstract Manifest newManifest(List references); 523 524 538 public abstract Manifest newManifest(List references, String id); 539 540 556 public abstract SignatureProperty newSignatureProperty 557 (List content, String target, String id); 558 559 574 public abstract SignatureProperties newSignatureProperties 575 (List properties, String id); 576 577 593 public abstract DigestMethod newDigestMethod(String algorithm, 594 DigestMethodParameterSpec params) throws NoSuchAlgorithmException , 595 InvalidAlgorithmParameterException ; 596 597 612 public abstract SignatureMethod newSignatureMethod(String algorithm, 613 SignatureMethodParameterSpec params) throws NoSuchAlgorithmException , 614 InvalidAlgorithmParameterException ; 615 616 631 public abstract Transform newTransform(String algorithm, 632 TransformParameterSpec params) throws NoSuchAlgorithmException , 633 InvalidAlgorithmParameterException ; 634 635 656 public abstract Transform newTransform(String algorithm, 657 XMLStructure params) throws NoSuchAlgorithmException , 658 InvalidAlgorithmParameterException ; 659 660 675 public abstract CanonicalizationMethod newCanonicalizationMethod( 676 String algorithm, C14NMethodParameterSpec params) 677 throws NoSuchAlgorithmException , InvalidAlgorithmParameterException ; 678 679 700 public abstract CanonicalizationMethod newCanonicalizationMethod( 701 String algorithm, XMLStructure params) 702 throws NoSuchAlgorithmException , InvalidAlgorithmParameterException ; 703 704 714 public final KeyInfoFactory getKeyInfoFactory() { 715 return KeyInfoFactory.getInstance(getMechanismType(), getProvider()); 716 } 717 718 732 public abstract XMLSignature unmarshalXMLSignature 733 (XMLValidateContext context) throws MarshalException; 734 735 751 public abstract XMLSignature unmarshalXMLSignature 752 (XMLStructure xmlStructure) throws MarshalException; 753 754 762 public abstract boolean isFeatureSupported(String feature); 763 764 771 public abstract URIDereferencer getURIDereferencer(); 772 } 773 | Popular Tags |