Class WSSecEncrypt
java.lang.Object
org.apache.ws.security.message.WSSecBase
org.apache.ws.security.message.WSSecEncryptedKey
org.apache.ws.security.message.WSSecEncrypt
Encrypts a parts of a message according to WS Specification, X509 profile,
and adds the encryption data.
- Author:
- Davanum Srinivas (dims@yahoo.com)., Werner Dittmann (Werner.Dittmann@apache.org).
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected byte[]protected Stringprotected Stringprotected SecurityTokenReferenceSecurityTokenReference to be inserted into EncryptedData/keyInfo element.protected Stringprotected SecretKeySymmetric key used in the EncrytpedKey.Fields inherited from class WSSecEncryptedKey
bstToken, document, encKeyId, encrUser, encryptedKeyElement, envelope, ephemeralKey, keyEncAlgo, keySize, useThisCert -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddExternalRefElement(Element dataRef, WSSecHeader secHeader) Adds (prepends) the external Reference element to the Security header.voidaddInternalRefElement(Element dataRef) Adds the internal Reference element to this Encrypt data.build(Document doc, Crypto crypto, WSSecHeader secHeader) Builds the SOAP envelope with encrypted Body and adds encrypted key.static ElementcreateDataRefList(Document doc, Element referenceList, Vector encDataRefs) Create DOM subtree forxenc:EncryptedKeyencryptForExternalRef(Element dataRef, Vector references) Encrypt one or more parts or elements of the message (external).encryptForInternalRef(Element dataRef, Vector references) Encrypt one or more parts or elements of the message (internal).Get the name of symmetric encryption algorithm to use.voidInitialize a WSSec Encrypt.voidsetEmbeddedKeyName(String embeddedKeyName) Set the key name for EMBEDDED_KEYNAMEvoidsetEncCanonicalization(String algo) Set the name of an optional canonicalization algorithm to use before encryption.voidsetKey(byte[] key) Sets the key to use during embedded encryption.voidSets the algorithm to encode the symmetric key.voidsetSecurityTokenReference(SecurityTokenReference reference) voidSet the name of the symmetric encryption algorithm to use.voidsetSymmetricKey(SecretKey key) Set the symmetric key to be used for encryptionMethods inherited from class WSSecEncryptedKey
appendBSTElementToHeader, appendToHeader, createCipherValue, createEnrcyptedKey, generateEphemeralKey, getBinarySecurityTokenElement, getBSTTokenId, getEncryptedKeyElement, getEphemeralKey, getId, prepareInternal, prependBSTElementToHeader, prependToHeader, setDocument, setEncKeyId, setEphemeralKey, setKeyEncAlgo, setKeySize, setUserInfo, setUseThisCertMethods inherited from class WSSecBase
getKeyIdentifierType, setBodyID, setKeyIdentifierType, setParts, setUserInfo, setWsConfig, setWsuId
-
Field Details
-
symEncAlgo
-
encCanonAlgo
-
embeddedKey
protected byte[] embeddedKey -
embeddedKeyName
-
symmetricKey
Symmetric key used in the EncrytpedKey. -
securityTokenReference
SecurityTokenReference to be inserted into EncryptedData/keyInfo element.
-
-
Constructor Details
-
WSSecEncrypt
public WSSecEncrypt()Constructor.
-
-
Method Details
-
setKey
public void setKey(byte[] key) Sets the key to use during embedded encryption.- Parameters:
key- to use during encryption. The key must fit the selected symmetrical encryption algorithm
-
setKeyEnc
Sets the algorithm to encode the symmetric key. Default is theWSConstants.KEYTRANSPORT_RSA15algorithm.- Parameters:
keyEnc- specifies the key encoding algorithm.- See Also:
-
setEmbeddedKeyName
Set the key name for EMBEDDED_KEYNAME- Parameters:
embeddedKeyName-
-
setSymmetricEncAlgorithm
Set the name of the symmetric encryption algorithm to use. This encryption alogrithm is used to encrypt the data. If the algorithm is not set then AES128 is used. Refer to WSConstants which algorithms are supported.- Parameters:
algo- Is the name of the encryption algorithm- See Also:
-
setEncCanonicalization
Set the name of an optional canonicalization algorithm to use before encryption. This c14n alogrithm is used to serialize the data before encryption. If the algorithm is not set then a standard serialization is used (provided by XMLCipher, usually a XMLSerializer according to DOM 3 specification).- Parameters:
algo- Is the name of the canonicalization algorithm
-
getSymmetricEncAlgorithm
Get the name of symmetric encryption algorithm to use. The name of the encryption alogrithm to encrypt the data, i.e. the SOAP Body. Refer to WSConstants which algorithms are supported.- Returns:
- the name of the currently selected symmetric encryption algorithm
- See Also:
-
prepare
Initialize a WSSec Encrypt. The method prepares and initializes a WSSec Encrypt structure after the relevant information was set. After preparartion of the token references can be added and encrypted. This method does not add any element to the security header. This must be done explicitly.- Overrides:
preparein classWSSecEncryptedKey- Parameters:
doc- The SOAP envelope asDocumentcrypto- An instance of the Crypto API to handle keystore and certificates- Throws:
WSSecurityException
-
build
public Document build(Document doc, Crypto crypto, WSSecHeader secHeader) throws WSSecurityException Builds the SOAP envelope with encrypted Body and adds encrypted key. This is a convenience method and for backward compatibility. The method calls the single function methods in order to perform a one shot encryption. This method is compatible with the build method of the previous version with the exception of the additional WSSecHeader parameter.- Parameters:
doc- the SOAP envelope asDocumentwith plaintext Bodycrypto- an instance of the Crypto API to handle keystore and CertificatessecHeader- the security header element to hold the encrypted key element.- Returns:
- the SOAP envelope with encrypted Body as
Document - Throws:
WSSecurityException
-
encryptForInternalRef
Encrypt one or more parts or elements of the message (internal). This method takes a vector ofWSEncryptionPartobject that contain information about the elements to encrypt. The method call the encryption method, takes the reference information generated during encryption and add this to thexenc:Referenceelement. This method can be called afterprepare()and can be called multiple times to encrypt a number of parts or elements. The method generates axenc:Referenceelement that must be added to this token. SeeaddInternalRefElement(). If thedataRefparameter isnullthe method creates and initializes a new Reference element.- Parameters:
dataRef- Axenc:Referenceelement ornullreferences- A vector containing WSEncryptionPart objects- Returns:
- Returns the updated
xenc:Referenceelement - Throws:
WSSecurityException
-
encryptForExternalRef
Encrypt one or more parts or elements of the message (external). This method takes a vector ofWSEncryptionPartobject that contain information about the elements to encrypt. The method call the encryption method, takes the reference information generated during encryption and add this to thexenc:Referenceelement. This method can be called afterprepare()and can be called multiple times to encrypt a number of parts or elements. The method generates axenc:Referenceelement that must be added to the SecurityHeader. SeeaddExternalRefElement(). If thedataRefparameter isnullthe method creates and initializes a new Reference element.- Parameters:
dataRef- Axenc:Referenceelement ornullreferences- A vector containing WSEncryptionPart objects- Returns:
- Returns the updated
xenc:Referenceelement - Throws:
WSSecurityException
-
addInternalRefElement
Adds the internal Reference element to this Encrypt data. The refernce element must be created by theencryptForInternalRef()method. The refernce element is added to theEncryptedKeyelement of this encrypt block.- Parameters:
dataRef- The internalenc:Referenceelement
-
addExternalRefElement
Adds (prepends) the external Reference element to the Security header. The refernce element must be created by theencryptForExternalRef()method. The method prepends the reference element in the SecurityHeader.- Parameters:
dataRef- The externalenc:ReferenceelementsecHeader- The security header.
-
createDataRefList
Create DOM subtree forxenc:EncryptedKey- Parameters:
doc- the SOAP enevelope parent documentkeyTransportAlgo- specifies which alogrithm to use to encrypt the symmetric key- Returns:
- an
xenc:EncryptedKeyelement
-
getSymmetricKey
- Returns:
- The symmetric key
-
setSymmetricKey
Set the symmetric key to be used for encryption- Parameters:
key-
-
getSecurityTokenReference
- Returns:
- Return the SecurityTokenRefernce
-
setSecurityTokenReference
- Parameters:
reference-
-