Class XMLEncryptionFactory
- java.lang.Object
-
- javax.xml.crypto.enc.XMLEncryptionFactory
-
public abstract class XMLEncryptionFactory extends java.lang.Object
A factory for creatingEncryptedType
objects (such asEncryptedData
,EncryptedKey
) from scratch or for unmarshalling anEncryptedType
object from a corresponding XML representation.XMLEncryptionFactory Type
Each instance of
XMLEncryptionFactory
supports a specific XML mechanism type. To create anXMLEncryptionFactory
, call one of the staticgetInstance
methods, passing in the XML mechanism type desired, for example:XMLEncryptionFactory factory = XMLEncryptionFactory.getInstance("DOM");
The objects that this factory produces will be based on DOM and abide by the DOM interoperability requirements as defined in the DOM Mechanism Requirements section of the API overview.
Note that a caller must use the same
XMLEncryptionFactory
instance to create theXMLStructure
s of a particularEncryptedType
that is to be generated. The behavior is undefined ifXMLStructure
s from different providers or different mechanism types are used together.Creating EncryptedDatas from scratch
Once the
XMLEncryptionFactory
has been created, objects can be instantiated by calling the appropriate method.Unmarshalling EncryptedData from XML
Alternatively, an
EncryptedData
may be created from an existing XML representation by invoking theunmarshalEncryptedType
method and passing it a mechanism-specificXMLDecryptContext
instance containing the XML content:DOMDecryptContext context = new DOMDecryptContext(key, encElement); EncryptedData data = (EncryptedData) factory.unmarshalEncryptedType(context);
EachXMLEncryptionFactory
must support the requiredXMLDecryptContext
types for that factory type, but may support others. A DOMXMLEncryptionFactory
must supportDOMDecryptContext
objects.Encrypting and Marshalling EncryptedData to XML
EachEncryptedData
created by the factory can also be marshalled back to an XML representation, by invoking theencrypt
method of theEncryptedData
object and passing it a mechanism-specificXMLEncryptContext
object that will hold the marshalled representation; for example:DOMEncryptContext context = new DOMEncryptContext(key, document); data.encrypt(context);
Concurrent AccessThe static methods of this class are guaranteed to be thread-safe. Multiple threads may concurrently invoke the static methods defined in this class with no ill effects.
However, this is not true for the non-static methods defined by this class. Unless otherwise documented by a specific provider, threads that need to access a single
XMLEncryptionFactory
instance concurrently should synchronize amongst themselves and provide the necessary locking. Multiple threads each manipulating a differentXMLEncryptionFactory
instance need not synchronize.
-
-
Field Summary
Fields Modifier and Type Field and Description private static java.lang.Class
cl
private static java.lang.reflect.Method
getImplMethod
private static java.lang.Class[]
getImplParams
private java.lang.String
mechanismType
private java.security.Provider
provider
-
Constructor Summary
Constructors Modifier Constructor and Description protected
XMLEncryptionFactory()
Default constructor, for invocation by subclasses.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method and Description private static XMLEncryptionFactory
findInstance(java.lang.String mechanismType, java.security.Provider provider)
static XMLEncryptionFactory
getInstance()
Returns anXMLEncryptionFactory
that supports the default XML processing mechanism and representation type ("DOM").static XMLEncryptionFactory
getInstance(java.lang.String mechanismType)
Returns anXMLEncryptionFactory
that supports the specified XML processing mechanism and representation type (ex: "DOM").static XMLEncryptionFactory
getInstance(java.lang.String mechanismType, java.security.Provider provider)
Returns anXMLEncryptionFactory
that supports the requested XML processing mechanism and representation type (ex: "DOM"), as supplied by the specified provider.static XMLEncryptionFactory
getInstance(java.lang.String mechanismType, java.lang.String provider)
Returns anXMLEncryptionFactory
that supports the requested XML processing mechanism and representation type (ex: "DOM"), as supplied by the specified provider.java.lang.String
getMechanismType()
Returns the type of the XML processing mechanism and representation supported by thisXMLEncryptionFactory
(ex: "DOM").java.security.Provider
getProvider()
Returns the provider of thisXMLEncryptionFactory
.abstract boolean
isFeatureSupported(java.lang.String feature)
Indicates whether a specified feature is supported.abstract AgreementMethod
newAgreementMethod(java.lang.String algorithm, byte[] kaNonce, KeyInfo originatorKeyInfo, KeyInfo recipientKeyInfo, AgreementMethodParameterSpec params)
Creates anAgreementMethod
.abstract CanonicalizationMethod
newCanonicalizationMethod(java.lang.String algorithm, C14NMethodParameterSpec params)
Creates aCanonicalizationMethod
for the specified algorithm URI and parameters.abstract CipherReference
newCipherReference(java.lang.String uri, java.util.List transforms)
Creates aCipherReference
from the specified parameters.abstract DataReference
newDataReference(java.lang.String uri, java.util.List content)
Creates aDataReference
from the specified URI.abstract DHKeyValue
newDHKeyValue(java.security.PublicKey key)
Creates a DHKeyValue from the specified keyabstract EncryptedData
newEncryptedData(ToBeEncrypted toBeEncrypted, EncryptionMethod encMethod, KeyInfo keyInfo, EncryptionProperties properties, java.lang.String id)
Creates anEncryptedData
which contains aCipherValue
.abstract EncryptedData
newEncryptedData(ToBeEncrypted toBeEncrypted, EncryptionMethod encMethod, KeyInfo keyInfo, EncryptionProperties properties, java.lang.String id, CipherReference cipherRef)
Creates anEncryptedData
which contains aCiphereReference
.abstract EncryptedKey
newEncryptedKey(ToBeEncryptedKey key, EncryptionMethod encMethod, KeyInfo keyInfo, EncryptionProperties properties, java.util.List references, java.lang.String id, java.lang.String carriedKeyName, java.lang.String recipient)
Creates anEncryptedKey
which contains aCipherValue
.abstract EncryptedKey
newEncryptedKey(ToBeEncryptedKey key, EncryptionMethod encMethod, KeyInfo keyInfo, EncryptionProperties properties, java.util.List references, java.lang.String id, java.lang.String carriedKeyName, java.lang.String recipient, CipherReference cipherRef)
Creates anEncryptedKey
.abstract EncryptionMethod
newEncryptionMethod(java.lang.String algorithm, java.lang.Integer keySize, EncryptionMethodParameterSpec params)
Creates aEncryptionMethod
for the specified algorithm URI, key size, and parameters.abstract EncryptionProperties
newEncryptionProperties(java.util.List properties, java.lang.String id)
Creates aEncryptionProperties
containing the specified list ofEncryptionProperty
s and optional id.abstract EncryptionProperty
newEncryptionProperty(java.util.List content, java.lang.String target, java.lang.String id, java.util.Map attributes)
Creates anEncryptionProperty
containing the specified list ofXMLStructure
s, target URI and optional id.abstract KeyReference
newKeyReference(java.lang.String uri, java.util.List content)
Creates aKeyReference
from the specified URI.abstract KeyInfo
newOriginatorKeyInfo(java.util.List content, java.lang.String id)
Creates an originator KeyInfo containing the specified list of key information.abstract KeyInfo
newRecipientKeyInfo(java.util.List content, java.lang.String id)
Creates a recipient KeyInfo containing the specified list of key information.abstract EncryptedType
unmarshalEncryptedType(XMLDecryptContext context)
Unmarshals a newEncryptedType
instance from a mechanism-specificXMLDecryptContext
instance.
-
-
-
Field Detail
-
mechanismType
private java.lang.String mechanismType
-
provider
private java.security.Provider provider
-
cl
private static java.lang.Class cl
-
getImplParams
private static final java.lang.Class[] getImplParams
-
getImplMethod
private static java.lang.reflect.Method getImplMethod
-
-
Constructor Detail
-
XMLEncryptionFactory
protected XMLEncryptionFactory()
Default constructor, for invocation by subclasses.
-
-
Method Detail
-
getInstance
public static XMLEncryptionFactory getInstance(java.lang.String mechanismType) throws NoSuchMechanismException
Returns anXMLEncryptionFactory
that supports the specified XML processing mechanism and representation type (ex: "DOM").This method uses the standard JCA provider lookup mechanism to locate and instantiate an
XMLEncryptionFactory
implementation of the desired mechanism type.- Parameters:
mechanismType
- the type of the XML processing mechanism and representation- Returns:
- a new
XMLEncryptionFactory
- Throws:
java.lang.NullPointerException
- ifmechanismType
isnull
NoSuchMechanismException
- if an implementation of the requestedmechanismType
cannot be found
-
findInstance
private static XMLEncryptionFactory findInstance(java.lang.String mechanismType, java.security.Provider provider)
-
getInstance
public static XMLEncryptionFactory getInstance(java.lang.String mechanismType, java.security.Provider provider) throws NoSuchMechanismException
Returns anXMLEncryptionFactory
that supports the requested XML processing mechanism and representation type (ex: "DOM"), as supplied by the specified provider.- Parameters:
mechanismType
- the type of the XML processing mechanism and representation. See the Service Providers section of the API overview for a list of standard mechanism types.provider
- the provider- Returns:
- a new
XMLEncryptionFactory
- Throws:
java.lang.NullPointerException
- ifprovider
ormechanismType
isnull
NoSuchMechanismException
- if an implementation of the requestedmechanismType
is not available from the specified provider
-
getInstance
public static XMLEncryptionFactory getInstance(java.lang.String mechanismType, java.lang.String provider) throws java.security.NoSuchProviderException, NoSuchMechanismException
Returns anXMLEncryptionFactory
that supports the requested XML processing mechanism and representation type (ex: "DOM"), as supplied by the specified provider.- Parameters:
mechanismType
- the type of the XML processing mechanism and representation. See the Service Providers section of the API overview for a list of standard mechanism types.provider
- the name of the provider- Returns:
- a new
XMLEncryptionFactory
- Throws:
java.security.NoSuchProviderException
- ifprovider
has not been configuredjava.lang.NullPointerException
- ifprovider
ormechanismType
isnull
NoSuchMechanismException
- if an implementation of the requestedmechanismType
is not available from the specified provider
-
getInstance
public static XMLEncryptionFactory getInstance() throws NoSuchMechanismException
Returns anXMLEncryptionFactory
that supports the default XML processing mechanism and representation type ("DOM").This method uses the standard JCA provider lookup mechanism to locate and instantiate an
XMLEncryptionFactory
implementation of the default mechanism type.- Returns:
- a new
XMLEncryptionFactory
- Throws:
NoSuchMechanismException
- if an implementation for the default mechanism type cannot be found
-
getMechanismType
public final java.lang.String getMechanismType()
Returns the type of the XML processing mechanism and representation supported by thisXMLEncryptionFactory
(ex: "DOM").- Returns:
- the XML processing mechanism type supported by this
XMLEncryptionFactory
-
getProvider
public final java.security.Provider getProvider()
Returns the provider of thisXMLEncryptionFactory
.- Returns:
- the provider of this
XMLEncryptionFactory
-
newEncryptedData
public abstract EncryptedData newEncryptedData(ToBeEncrypted toBeEncrypted, EncryptionMethod encMethod, KeyInfo keyInfo, EncryptionProperties properties, java.lang.String id)
Creates anEncryptedData
which contains aCipherValue
.- Parameters:
toBeEncrypted
- the data to be encrypted in this EncryptedDataencMethod
- the encryption method (may benull
)keyInfo
- the key info (may benull
)properties
- the encryption properties (may benull
)id
- the ID (may benull
)- Returns:
- an
EncryptedData
- Throws:
java.lang.IllegalArgumentException
- if ToBeEncryptedKey is passed in as toBeEncryptedjava.lang.NullPointerException
- iftoBeEncrypted
is null.
-
newEncryptedData
public abstract EncryptedData newEncryptedData(ToBeEncrypted toBeEncrypted, EncryptionMethod encMethod, KeyInfo keyInfo, EncryptionProperties properties, java.lang.String id, CipherReference cipherRef)
Creates anEncryptedData
which contains aCiphereReference
.- Parameters:
toBeEncrypted
- the data to be encrypted in this EncryptedDataencMethod
- the encryption method (may benull
)keyInfo
- the key info (may benull
)properties
- the encryption properties (may benull
)id
- the ID (may benull
)cipherRef
- the CiphereReference this EncryptedData will contain- Returns:
- an
EncryptedData
- Throws:
java.lang.IllegalArgumentException
- if ToBeEncryptedKey is passed in as toBeEncryptedjava.lang.NullPointerException
- iftoBeEncrypted
orcipherRef
is null
-
newDataReference
public abstract DataReference newDataReference(java.lang.String uri, java.util.List content)
Creates aDataReference
from the specified URI.- Parameters:
uri
- the uri that refers to anEncryptedData
elementcontent
- a list ofXMLStructure
s (may be null or empty). The list is defensively copied to protect against subsequent modification.- Returns:
- a
DataReference
- Throws:
java.lang.IllegalArgumentException
- ifuri
is not RFC2396 compliantjava.lang.ClassCastException
- ifcontent
contains any entries that are not of typeXMLStructure
java.lang.NullPointerException
- ifuri
isnull
-
newKeyReference
public abstract KeyReference newKeyReference(java.lang.String uri, java.util.List content)
Creates aKeyReference
from the specified URI.- Parameters:
uri
- the uri that refers to anEncryptedKey
elementcontent
- a list ofXMLStructure
s (may be null or empty). The list is defensively copied to protect against subsequent modification.- Returns:
- a
KeyReference
- Throws:
java.lang.IllegalArgumentException
- ifuri
is not RFC2396 compliantjava.lang.ClassCastException
- ifcontent
contains any entries that are not of typeXMLStructure
java.lang.NullPointerException
- ifuri
isnull
-
newEncryptionProperty
public abstract EncryptionProperty newEncryptionProperty(java.util.List content, java.lang.String target, java.lang.String id, java.util.Map attributes)
Creates anEncryptionProperty
containing the specified list ofXMLStructure
s, target URI and optional id.- Parameters:
content
- a list of one or moreXMLStructure
s. The list is defensively copied to protect against subsequent modification.target
- the target URI of theEncryptedType
that this property applies to (may benull
)id
- the id (may benull
)attributes
- a map of attributes from the XML namespace (may be empty ornull
). The map is defensively copied to protect against subsequent modification.- Returns:
- an
EncryptionProperty
- Throws:
java.lang.NullPointerException
- ifcontent
isnull
java.lang.IllegalArgumentException
- ifcontent
is empty or one or more of theattributes
are not from the XML namespacejava.lang.ClassCastException
- ifcontent
contains any entries that are not of typeXMLStructure
-
newEncryptionProperties
public abstract EncryptionProperties newEncryptionProperties(java.util.List properties, java.lang.String id)
Creates aEncryptionProperties
containing the specified list ofEncryptionProperty
s and optional id.- Parameters:
properties
- a list of one or moreEncryptionProperty
s. The list is defensively copied to protect against subsequent modification.id
- the id (may benull
)- Returns:
- a
EncryptionProperties
- Throws:
java.lang.NullPointerException
- ifproperties
isnull
java.lang.IllegalArgumentException
- ifproperties
is emptyjava.lang.ClassCastException
- ifproperties
contains any entries that are not of typeEncryptionProperty
-
newEncryptionMethod
public abstract EncryptionMethod newEncryptionMethod(java.lang.String algorithm, java.lang.Integer keySize, EncryptionMethodParameterSpec params) throws java.security.NoSuchAlgorithmException, java.security.InvalidAlgorithmParameterException
Creates aEncryptionMethod
for the specified algorithm URI, key size, and parameters.- Parameters:
algorithm
- the URI identifying the encryption algorithm. Supported algorithms are defined in EncryptionMethod interface.keySize
- the size of the key to be used (ornull
if not applicable)ivSpec
- the initialization vector (ornull
if not applicable)params
- algorithm-specific encryption parameters (may benull
)- Returns:
- the
EncryptionMethod
- Throws:
java.security.InvalidAlgorithmParameterException
- if the specified parameters are inappropriate for the requested algorithmjava.security.NoSuchAlgorithmException
- if an implementation of the specified algorithm cannot be foundjava.lang.NullPointerException
- ifalgorithm
isnull
-
newCipherReference
public abstract CipherReference newCipherReference(java.lang.String uri, java.util.List transforms)
Creates aCipherReference
from the specified parameters.- Parameters:
uri
- the URI that identifies the encrypted octet sequencetransforms
- a list ofTransform
s. The list is defensively copied to protect against subsequent modification. May be null or empty.- Returns:
- a
CipherReference
- Throws:
java.lang.IllegalArgumentException
- ifuri
is not RFC2396 compliantjava.lang.NullPointerException
- ifuri
isnull
java.lang.ClassCastException
- iftransforms
contains any entries that are not of type Transform
-
newCanonicalizationMethod
public abstract CanonicalizationMethod newCanonicalizationMethod(java.lang.String algorithm, C14NMethodParameterSpec params) throws java.security.NoSuchAlgorithmException, java.security.InvalidAlgorithmParameterException
Creates aCanonicalizationMethod
for the specified algorithm URI and parameters.- Parameters:
algorithm
- the URI identifying the canonicalization algorithmparams
- algorithm-specific canonicalization parameters (may benull
)- Returns:
- the
CanonicalizationMethod
- Throws:
java.security.InvalidAlgorithmParameterException
- if the specified parameters are inappropriate for the requested algorithmjava.security.NoSuchAlgorithmException
- if an implementation of the specified algorithm cannot be foundjava.lang.NullPointerException
- ifalgorithm
isnull
-
unmarshalEncryptedType
public abstract EncryptedType unmarshalEncryptedType(XMLDecryptContext context) throws MarshalException
Unmarshals a newEncryptedType
instance from a mechanism-specificXMLDecryptContext
instance.- Parameters:
context
- the mechanism-specific decryption context- Returns:
- the
EncryptedType
- Throws:
java.lang.NullPointerException
- ifcontext
isnull
java.lang.ClassCastException
- if the type ofcontext
is inappropriate for this factoryMarshalException
- if an unrecoverable exception occurs during unmarshalling
-
isFeatureSupported
public abstract boolean isFeatureSupported(java.lang.String feature)
Indicates whether a specified feature is supported.- Parameters:
feature
- the feature name (as an absolute URI)- Returns:
true
if the specified feature is supported,false
otherwise- Throws:
java.lang.NullPointerException
- iffeature
isnull
-
newAgreementMethod
public abstract AgreementMethod newAgreementMethod(java.lang.String algorithm, byte[] kaNonce, KeyInfo originatorKeyInfo, KeyInfo recipientKeyInfo, AgreementMethodParameterSpec params) throws java.security.NoSuchAlgorithmException, java.security.InvalidAlgorithmParameterException
Creates anAgreementMethod
.- Parameters:
algorithm
- the URI identifying the key agreement algorithmkaNonce
- the KA-Nonce (may benull
). The value of kaNonce is cloned to protect against subsequent modificationoriginatorKeyInfo
- the originator's key info (may benull
)recipientKeyInfo
- the recipient's key info (may benull
)params
- algorithm-specific agreement method parameters (may benull
)- Returns:
- the
AgreementMethod
- Throws:
java.security.InvalidAlgorithmParameterException
- if the specified parameters are inappropriate for the requested algorithmjava.security.NoSuchAlgorithmException
- if an implementation of the specified algorithm cannot be foundjava.lang.NullPointerException
- ifalgorithm
isnull
-
newEncryptedKey
public abstract EncryptedKey newEncryptedKey(ToBeEncryptedKey key, EncryptionMethod encMethod, KeyInfo keyInfo, EncryptionProperties properties, java.util.List references, java.lang.String id, java.lang.String carriedKeyName, java.lang.String recipient)
Creates anEncryptedKey
which contains aCipherValue
.- Parameters:
key
- the key to be encryptedencMethod
- the encryption method (may benull
)keyInfo
- the key info (may benull
)properties
- the encryption properties (may benull
)references
- a list ofDataReference
s orKeyReference
s (may benull
or empty)id
- the ID of the EncryptedKeyElement (may benull
)carriedKeyName
- the carried key name (may benull
)recipient
- the recipient (may benull
)- Returns:
- an
EncryptedKey
- Throws:
java.lang.ClassCastException
- ifreferences
contains any entries that are not of typeDataReference
orKeyReference
java.lang.NullPointerException
- ifkey
isnull
-
newEncryptedKey
public abstract EncryptedKey newEncryptedKey(ToBeEncryptedKey key, EncryptionMethod encMethod, KeyInfo keyInfo, EncryptionProperties properties, java.util.List references, java.lang.String id, java.lang.String carriedKeyName, java.lang.String recipient, CipherReference cipherRef)
Creates anEncryptedKey
.- Parameters:
key
- the key to be encryptedencMethod
- the encryption method (may benull
)keyInfo
- the key info (may benull
)properties
- the encryption properties (may benull
)references
- a list ofDataReference
s orKeyReference
s (may benull
or empty)id
- the ID of the EncryptedKey element (may benull
)carriedKeyName
- the carried key name (may benull
)recipient
- the recipient (may benull
)cipherRef
- the CiphereReference this EncryptedData will contain- Returns:
- an
EncryptedKey
- Throws:
java.lang.ClassCastException
- ifreferences
contains any entries that are not of typeDataReference
orKeyReference
java.lang.NullPointerException
- ifkey
orcipherRef
is null
-
newOriginatorKeyInfo
public abstract KeyInfo newOriginatorKeyInfo(java.util.List content, java.lang.String id)
Creates an originator KeyInfo containing the specified list of key information.- Parameters:
content
- a list of one or more XMLStructures representing key information types. The list is defensively copied to protect against subsequent modification.id
- the value of an XML ID (may be null)- Returns:
- an originator KeyInfo
- Throws:
java.lang.NullPointerException
- if content is nulljava.lang.IllegalArgumentException
- if content is emptyjava.lang.ClassCastException
- if content contains any entities that are not of type XMLStructure
-
newRecipientKeyInfo
public abstract KeyInfo newRecipientKeyInfo(java.util.List content, java.lang.String id)
Creates a recipient KeyInfo containing the specified list of key information.- Parameters:
content
- a list of one or more XMLStructures representing key information types. The list is defensively copied to protect against subsequent modification.the
- value of an XML ID (may be null)- Returns:
- a recipient KeyInfo
- Throws:
java.lang.NullPointerException
- if content is nulljava.lang.IllegalArgumentException
- if content is emptyjava.lang.ClassCastException
- if content contains any entities that are not of type XMLStructure
-
newDHKeyValue
public abstract DHKeyValue newDHKeyValue(java.security.PublicKey key) throws java.security.KeyException
Creates a DHKeyValue from the specified key- Parameters:
key
- the public key for DH algorithm- Throws:
java.security.KeyException
- if the key can not be used to create the DHKeyValuejava.lang.NullPointerException
- if the key is null
-
-