org.apache.ws.security.message
Class WSSecEncrypt

java.lang.Object
  extended by org.apache.ws.security.message.WSSecBase
      extended by org.apache.ws.security.message.WSSecEncryptedKey
          extended by org.apache.ws.security.message.WSSecEncrypt

public class WSSecEncrypt
extends WSSecEncryptedKey

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
protected  byte[] embeddedKey
           
protected  String embeddedKeyName
           
protected  SecurityTokenReference securityTokenReference
          SecurityTokenReference to be inserted into EncryptedData/keyInfo element.
 
Fields inherited from class org.apache.ws.security.message.WSSecEncryptedKey
bstToken, customEKTokenId, customEKTokenValueType, document, encKeyId, encrUser, encryptedEphemeralKey, encryptedKeyElement, envelope, ephemeralKey, keyEncAlgo, symEncAlgo, symmetricKey, useThisCert
 
Fields inherited from class org.apache.ws.security.message.WSSecBase
callbackLookup, doDebug, keyIdentifierType, parts, password, user
 
Constructor Summary
WSSecEncrypt()
           
WSSecEncrypt(WSSConfig config)
           
 
Method Summary
 void addExternalRefElement(Element dataRef, WSSecHeader secHeader)
          Adds (prepends) the external Reference element to the Security header.
 void addInternalRefElement(Element dataRef)
          Adds the internal Reference element to this Encrypt data.
 Document build(Document doc, Crypto crypto, WSSecHeader secHeader)
          Builds the SOAP envelope with encrypted Body and adds encrypted key.
static Element createDataRefList(Document doc, Element referenceList, List<String> encDataRefs)
          Create DOM subtree for xenc:EncryptedKey
static List<String> doEncryption(Document doc, WSSConfig config, org.apache.xml.security.keys.KeyInfo keyInfo, SecretKey secretKey, String encryptionAlgorithm, List<WSEncryptionPart> references, CallbackLookup callbackLookup)
          Perform encryption on the SOAP envelope.
 Element encryptForExternalRef(Element dataRef, List<WSEncryptionPart> references)
          Deprecated. Use encryptForRef(dataRef, references) instead
 Element encryptForInternalRef(Element dataRef, List<WSEncryptionPart> references)
          Deprecated. Use encryptForRef(dataRef, references) instead
 Element encryptForRef(Element dataRef, List<WSEncryptionPart> references)
          Encrypt one or more parts or elements of the message.
 SecurityTokenReference getSecurityTokenReference()
           
 boolean isEmbedEncryptedKey()
           
 boolean isEncryptSymmKey()
           
 void prepare(Document doc, Crypto crypto)
          Initialize a WSSec Encrypt.
 void setCustomReferenceValue(String customReferenceValue)
           
 void setEmbeddedKeyName(String embeddedKeyName)
          Set the key name for EMBEDDED_KEYNAME
 void setEmbedEncryptedKey(boolean embedEncryptedKey)
           
 void setEncKeyIdDirectId(boolean b)
           
 void setEncryptSymmKey(boolean encryptSymmKey)
           
 void setKey(byte[] key)
          Sets the key to use during embedded encryption.
 void setKeyEnc(String keyEnc)
          Sets the algorithm to encode the symmetric key.
 void setSecurityTokenReference(SecurityTokenReference reference)
           
 
Methods inherited from class org.apache.ws.security.message.WSSecEncryptedKey
appendBSTElementToHeader, appendToHeader, createCipherValue, createEncryptedKey, getBinarySecurityTokenElement, getBSTTokenId, getEncryptedEphemeralKey, getEncryptedKeyElement, getEphemeralKey, getId, getKeyGenerator, getSymmetricEncAlgorithm, getSymmetricKey, isCertSet, prepareInternal, prependBSTElementToHeader, prependToHeader, setCustomEKTokenId, setCustomEKTokenValueType, setDocument, setEncKeyId, setEncryptedKeyElement, setEphemeralKey, setKeyEncAlgo, setSymmetricEncAlgorithm, setSymmetricKey, setUserInfo, setUseThisCert
 
Methods inherited from class org.apache.ws.security.message.WSSecBase
getKeyIdentifierType, getWsConfig, setBodyID, setCallbackLookup, setKeyIdentifierType, setParts, setUserInfo, setWsConfig, setWsuId
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

embeddedKey

protected byte[] embeddedKey

embeddedKeyName

protected String embeddedKeyName

securityTokenReference

protected SecurityTokenReference securityTokenReference
SecurityTokenReference to be inserted into EncryptedData/keyInfo element.

Constructor Detail

WSSecEncrypt

public WSSecEncrypt()

WSSecEncrypt

public WSSecEncrypt(WSSConfig config)
Method Detail

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

public void setKeyEnc(String keyEnc)
Sets the algorithm to encode the symmetric key. Default is the WSConstants.KEYTRANSPORT_RSA15 algorithm.

Parameters:
keyEnc - specifies the key encoding algorithm.
See Also:
WSConstants.KEYTRANSPORT_RSA15, WSConstants.KEYTRANSPORT_RSAOEP

setEmbeddedKeyName

public void setEmbeddedKeyName(String embeddedKeyName)
Set the key name for EMBEDDED_KEYNAME

Parameters:
embeddedKeyName -

prepare

public void prepare(Document doc,
                    Crypto crypto)
             throws WSSecurityException
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:
prepare in class WSSecEncryptedKey
Parameters:
doc - The SOAP envelope as Document
crypto - 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 as Document with plain text Body
crypto - an instance of the Crypto API to handle keystore and Certificates
secHeader - the security header element to hold the encrypted key element.
Returns:
the SOAP envelope with encrypted Body as Document
Throws:
WSSecurityException

encryptForRef

public Element encryptForRef(Element dataRef,
                             List<WSEncryptionPart> references)
                      throws WSSecurityException
Encrypt one or more parts or elements of the message. This method takes a vector of WSEncryptionPart object 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 the xenc:Reference element. This method can be called after prepare() and can be called multiple times to encrypt a number of parts or elements. The method generates a xenc:Reference element that must be added to this token. See addInternalRefElement(). If the dataRef parameter is null the method creates and initializes a new Reference element.

Parameters:
dataRef - A xenc:Reference element or null
references - A list containing WSEncryptionPart objects
Returns:
Returns the updated xenc:Reference element
Throws:
WSSecurityException

encryptForInternalRef

public Element encryptForInternalRef(Element dataRef,
                                     List<WSEncryptionPart> references)
                              throws WSSecurityException
Deprecated. Use encryptForRef(dataRef, references) instead

Throws:
WSSecurityException

encryptForExternalRef

public Element encryptForExternalRef(Element dataRef,
                                     List<WSEncryptionPart> references)
                              throws WSSecurityException
Deprecated. Use encryptForRef(dataRef, references) instead

Throws:
WSSecurityException

addInternalRefElement

public void addInternalRefElement(Element dataRef)
Adds the internal Reference element to this Encrypt data. The reference element must be created by the encryptForInternalRef() method. The reference element is added to the EncryptedKey element of this encrypt block.

Parameters:
dataRef - The internal enc:Reference element

addExternalRefElement

public void addExternalRefElement(Element dataRef,
                                  WSSecHeader secHeader)
Adds (prepends) the external Reference element to the Security header. The reference element must be created by the encryptForExternalRef() method. The method prepends the reference element in the SecurityHeader.

Parameters:
dataRef - The external enc:Reference element
secHeader - The security header.

doEncryption

public static List<String> doEncryption(Document doc,
                                        WSSConfig config,
                                        org.apache.xml.security.keys.KeyInfo keyInfo,
                                        SecretKey secretKey,
                                        String encryptionAlgorithm,
                                        List<WSEncryptionPart> references,
                                        CallbackLookup callbackLookup)
                                 throws WSSecurityException
Perform encryption on the SOAP envelope.

Parameters:
doc - The document containing the SOAP envelope as document element
config - The WSSConfig from which to generate wsu:ID's
keyInfo - The KeyInfo object to set in EncryptedData
secretKey - The SecretKey object with which to encrypt data
encryptionAlgorithm - The encryption algorithm URI to use
references - The list of references to encrypt
Returns:
a List of references to EncryptedData elements
Throws:
WSSecurityException

createDataRefList

public static Element createDataRefList(Document doc,
                                        Element referenceList,
                                        List<String> encDataRefs)
Create DOM subtree for xenc:EncryptedKey

Parameters:
doc - the SOAP envelope parent document
referenceList -
encDataRefs -
Returns:
an xenc:EncryptedKey element

getSecurityTokenReference

public SecurityTokenReference getSecurityTokenReference()
Returns:
Return the SecurityTokenRefernce

setSecurityTokenReference

public void setSecurityTokenReference(SecurityTokenReference reference)
Parameters:
reference -

isEncryptSymmKey

public boolean isEncryptSymmKey()

setEncryptSymmKey

public void setEncryptSymmKey(boolean encryptSymmKey)

setCustomReferenceValue

public void setCustomReferenceValue(String customReferenceValue)

setEncKeyIdDirectId

public void setEncKeyIdDirectId(boolean b)

setEmbedEncryptedKey

public void setEmbedEncryptedKey(boolean embedEncryptedKey)

isEmbedEncryptedKey

public boolean isEmbedEncryptedKey()


Copyright © 2004-2013 The Apache Software Foundation. All Rights Reserved.