Package org.apache.wss4j.dom.message
Class WSSecEncrypt
java.lang.Object
org.apache.wss4j.dom.message.WSSecBase
org.apache.wss4j.dom.message.WSSecEncryptedKey
org.apache.wss4j.dom.message.WSSecEncrypt
Encrypts a parts of a message according to WS Specification, X509 profile,
and adds the encryption data.
-
Field Summary
Fields inherited from class org.apache.wss4j.dom.message.WSSecBase
addWSUNamespace, attachmentCallbackHandler, callbackLookup, expandXopInclude, keyIdentifierType, password, storeBytesInAttachment, user -
Constructor Summary
ConstructorsConstructorDescriptionWSSecEncrypt(WSSecHeader securityHeader) WSSecEncrypt(Document doc) WSSecEncrypt(Document doc, Provider provider) -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidaddExternalRefElement(Element dataRef) Adds (prepends) the external Reference element to the Security header.voidaddInternalRefElement(Element dataRef) Adds the internal Reference element to this Encrypt data.Builds the SOAP envelope with encrypted Body and adds encrypted key.static ElementcreateDataRefList(Document doc, Element referenceList, List<String> encDataRefs) Create DOM subtree forxenc:EncryptedKeyPerform encryption using the given symmetric keyencryptForRef(Element dataRef, List<WSEncryptionPart> references, SecretKey symmetricKey) Encrypt one or more parts or elements of the message.org.apache.xml.security.encryption.SerializerGet the name of symmetric encryption algorithm to use.booleanbooleanvoidInitialize a WSSec Encrypt.voidsetCustomReferenceValue(String customReferenceValue) voidsetEmbedEncryptedKey(boolean embedEncryptedKey) voidsetEncKeyIdDirectId(boolean b) voidsetEncryptionSerializer(org.apache.xml.security.encryption.Serializer encryptionSerializer) voidsetEncryptSymmKey(boolean encryptSymmKey) voidsetSecurityTokenReference(SecurityTokenReference reference) voidSet the name of the symmetric encryption algorithm to use.Methods inherited from class org.apache.wss4j.dom.message.WSSecEncryptedKey
addCipherValueElement, appendBSTElementToHeader, appendToHeader, createCipherValue, createEncryptedKeyElement, createEncryptedKeyElement, getBinarySecurityTokenElement, getBSTTokenId, getCustomEKKeyInfoElement, getDigestAlgorithm, getEncryptedKeyElement, getEncryptedKeySHA1, getId, getKeyAgreementMethod, getKeyEncAlgo, getMGFAlgorithm, getUseThisCert, getUseThisPublicKey, isCertSet, isIncludeEncryptionToken, prependBSTElementToHeader, prependToHeader, setCustomEKKeyInfoElement, setCustomEKTokenId, setCustomEKTokenValueType, setDigestAlgorithm, setEncKeyId, setEncryptedKeyElement, setEncryptedKeySHA1, setIncludeEncryptionToken, setKeyAgreementMethod, setKeyEncAlgo, setMGFAlgorithm, setUserInfo, setUseThisCert, setUseThisPublicKeyMethods inherited from class org.apache.wss4j.dom.message.WSSecBase
clean, getDocument, getIdAllocator, getKeyIdentifierType, getParts, getSecurityHeader, getWsDocInfo, isExpandXopInclude, setAttachmentCallbackHandler, setBodyID, setCallbackLookup, setExpandXopInclude, setIdAllocator, setKeyIdentifierType, setStoreBytesInAttachment, setUserInfo, setWsDocInfo, setWsuId
-
Constructor Details
-
WSSecEncrypt
-
WSSecEncrypt
-
WSSecEncrypt
-
-
Method Details
-
prepare
Initialize a WSSec Encrypt. The method prepares and initializes a WSSec Encrypt structure after the relevant information was set. After preparation 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:
crypto- An instance of the Crypto API to handle keystore and certificatessymmetricKey- The symmetric key to use for encryption- Throws:
WSSecurityException
-
build
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.- Parameters:
crypto- an instance of the Crypto API to handle keystore and CertificatessymmetricKey- The symmetric key to use for encryption- Returns:
- the SOAP envelope with encrypted Body as
Document - Throws:
WSSecurityException
-
encrypt
Perform encryption using the given symmetric key- Parameters:
symmetricKey- The symmetric key to use for encryption- Returns:
- the EncryptedData element
- Throws:
WSSecurityException
-
encryptForRef
public Element encryptForRef(Element dataRef, List<WSEncryptionPart> references, SecretKey symmetricKey) throws WSSecurityException Encrypt one or more parts or elements of the message. This method takes a list 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 list containing WSEncryptionPart objectssymmetricKey- The symmetric key to use for encryption- Returns:
- Returns the updated
xenc:Referenceelement - Throws:
WSSecurityException
-
addInternalRefElement
Adds the internal Reference element to this Encrypt data. The reference element must be created by theencryptForInternalRef()method. The reference 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 reference element must be created by theencryptForExternalRef()method. The method prepends the reference element in the SecurityHeader.- Parameters:
dataRef- The externalenc:Referenceelement
-
addAttachmentEncryptedDataElements
public void addAttachmentEncryptedDataElements() -
createDataRefList
public static Element createDataRefList(Document doc, Element referenceList, List<String> encDataRefs) Create DOM subtree forxenc:EncryptedKey- Parameters:
doc- the SOAP envelope parent documentreferenceList-encDataRefs-- Returns:
- an
xenc:EncryptedKeyelement
-
getSecurityTokenReference
- Returns:
- Return the SecurityTokenRefernce
-
setSecurityTokenReference
- Parameters:
reference-
-
isEncryptSymmKey
public boolean isEncryptSymmKey() -
setEncryptSymmKey
public void setEncryptSymmKey(boolean encryptSymmKey) -
setCustomReferenceValue
-
setEncKeyIdDirectId
public void setEncKeyIdDirectId(boolean b) -
setEmbedEncryptedKey
public void setEmbedEncryptedKey(boolean embedEncryptedKey) -
isEmbedEncryptedKey
public boolean isEmbedEncryptedKey() -
getAttachmentEncryptedDataElements
-
getEncryptionSerializer
public org.apache.xml.security.encryption.Serializer getEncryptionSerializer() -
setEncryptionSerializer
public void setEncryptionSerializer(org.apache.xml.security.encryption.Serializer encryptionSerializer) -
setSymmetricEncAlgorithm
Set the name of the symmetric encryption algorithm to use. This encryption algorithm 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:
-
getSymmetricEncAlgorithm
Get the name of symmetric encryption algorithm to use. The name of the encryption algorithm 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:
-