Package org.apache.wss4j.dom.message
Class WSSecEncryptedKey
java.lang.Object
org.apache.wss4j.dom.message.WSSecBase
org.apache.wss4j.dom.message.WSSecEncryptedKey
- Direct Known Subclasses:
WSSecEncrypt
Builder class to build an EncryptedKey.
This is especially useful in the case where the same
EncryptedKey has to be used to sign and encrypt the message In
such a situation this builder will add the EncryptedKey to the
security header and we can use the information form the builder to provide to
other builders to reference to the token-
Field Summary
Fields inherited from class org.apache.wss4j.dom.message.WSSecBase
addWSUNamespace, attachmentCallbackHandler, callbackLookup, expandXopInclude, keyIdentifierType, password, storeBytesInAttachment, user -
Constructor Summary
ConstructorsConstructorDescriptionWSSecEncryptedKey(WSSecHeader securityHeader) WSSecEncryptedKey(Document doc, Provider provider) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddCipherValueElement(byte[] encryptedEphemeralKey) Create and add the CipherValue Element to the EncryptedKey Element.voidAppend the BinarySecurityToken to the elements already in the Security header.voidAppend the EncryptedKey element to the elements already in the Security header.protected ElementcreateCipherValue(Document doc, Element encryptedKey) protected voidcreateEncryptedKeyElement(X509Certificate remoteCert, Crypto crypto, org.apache.xml.security.encryption.params.KeyAgreementParameters dhSpec) Now we need to set up the EncryptedKey header block: 1) create a EncryptedKey element and set a wsu:Id for it 2) Generate ds:KeyInfo element 3) Create and set up the ds:KeyInfo child element - this can either be a SecurityTokenReference or X509Data/X509SKI 4) Create the CipherValue element structure and insert the encrypted session keyprotected voidNow we need to setup the EncryptedKey header block: 1) create a EncryptedKey element and set a wsu:Id for it 2) Generate ds:KeyInfo element, this wraps the wsse:SecurityTokenReference 3) Create and set up the SecurityTokenReference according to the keyIdentifier parameter 4) Create the CipherValue element structure and insert the encrypted session keyGet the id of the BSt generated duringprepare().Get the digest algorithm to use with the RSA-OAEP key transport algorithm.getId()Get the id generated duringprepare().org.apache.xml.security.encryption.params.KeyDerivationParametersGet the MGF algorithm to use with the RSA-OAEP key transport algorithm.booleanbooleanvoidCreate the EncryptedKey Element for inclusion in the security header, by encrypting the symmetricKey parameter using either a public key or certificate that is set on the class, and adding the encrypted bytes as the CipherValue of the EncryptedKey element.voidPrepend the BinarySecurityToken to the elements already in the Security header.voidPrepend the EncryptedKey element to the elements already in the Security header.voidsetCustomEKKeyInfoElement(Element customEKKeyInfoElement) voidsetCustomEKTokenId(String customEKTokenId) voidsetCustomEKTokenValueType(String customEKTokenValueType) voidsetDigestAlgorithm(String digestAlgorithm) Set the digest algorithm to use with the RSA-OAEP key transport algorithm.voidsetEncKeyId(String encKeyId) voidsetEncryptedKeyElement(Element encryptedKeyElement) Set the encrypted key element when a pre prepared encrypted key is usedprotected voidsetEncryptedKeySHA1(byte[] encryptedEphemeralKey) voidsetIncludeEncryptionToken(boolean includeEncryptionToken) voidsetKeyAgreementMethod(String keyAgreementMethod) voidsetKeyDerivationMethod(String keyDerivationMethod) voidsetKeyDerivationParameters(org.apache.xml.security.encryption.params.KeyDerivationParameters keyDerivationParameters) voidsetKeyEncAlgo(String keyEncAlgo) voidsetMGFAlgorithm(String mgfAlgorithm) Set the MGF algorithm to use with the RSA-OAEP key transport algorithm.voidsetUserInfo(String user) Set the user name to get the encryption certificate.voidSet the X509 Certificate to use for encryption.voidSet the PublicKey to use for encryption.Methods 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
-
WSSecEncryptedKey
-
WSSecEncryptedKey
-
WSSecEncryptedKey
-
-
Method Details
-
setUserInfo
Set the user name to get the encryption certificate. The public key of this certificate is used, thus no password necessary. The user name is a keystore alias usually.- Parameters:
user-
-
getId
Get the id generated duringprepare(). Returns the the value of wsu:Id attribute of the EncryptedKey element.- Returns:
- Return the wsu:Id of this token or null if
prepare()was not called before.
-
prepare
Create the EncryptedKey Element for inclusion in the security header, by encrypting the symmetricKey parameter using either a public key or certificate that is set on the class, and adding the encrypted bytes as the CipherValue of the EncryptedKey element. The KeyInfo is constructed according to the keyIdentifierType and also the type of the encrypting key- Parameters:
crypto- An instance of the Crypto API to handle keystore and certificatessymmetricKey- The symmetric key to encrypt and insert into the EncryptedKey- Throws:
WSSecurityException
-
addCipherValueElement
Create and add the CipherValue Element to the EncryptedKey Element.- Throws:
WSSecurityException
-
createEncryptedKeyElement
protected void createEncryptedKeyElement(X509Certificate remoteCert, Crypto crypto, org.apache.xml.security.encryption.params.KeyAgreementParameters dhSpec) throws WSSecurityException Now we need to set up the EncryptedKey header block: 1) create a EncryptedKey element and set a wsu:Id for it 2) Generate ds:KeyInfo element 3) Create and set up the ds:KeyInfo child element - this can either be a SecurityTokenReference or X509Data/X509SKI 4) Create the CipherValue element structure and insert the encrypted session key- Throws:
WSSecurityException
-
createEncryptedKeyElement
Now we need to setup the EncryptedKey header block: 1) create a EncryptedKey element and set a wsu:Id for it 2) Generate ds:KeyInfo element, this wraps the wsse:SecurityTokenReference 3) Create and set up the SecurityTokenReference according to the keyIdentifier parameter 4) Create the CipherValue element structure and insert the encrypted session key- Throws:
WSSecurityException
-
createCipherValue
-
prependToHeader
public void prependToHeader()Prepend the EncryptedKey element to the elements already in the Security header. The method can be called any time afterprepare(). This allows to insert the EncryptedKey element at any position in the Security header. -
appendToHeader
public void appendToHeader()Append the EncryptedKey element to the elements already in the Security header. The method can be called any time afterprepare(). This allows to insert the EncryptedKey element at any position in the Security header. -
prependBSTElementToHeader
public void prependBSTElementToHeader()Prepend the BinarySecurityToken to the elements already in the Security header. The method can be called any time afterprepare(). This allows to insert the BST element at any position in the Security header. -
appendBSTElementToHeader
public void appendBSTElementToHeader()Append the BinarySecurityToken to the elements already in the Security header. The method can be called any time afterprepare(). This allows to insert the BST element at any position in the Security header. -
setUseThisCert
Set the X509 Certificate to use for encryption. If this is set and the key identifier is set toDirectReferencethen use this certificate to get the public key for encryption.- Parameters:
cert- is the X509 certificate to use for encryption
-
getUseThisCert
-
setUseThisPublicKey
Set the PublicKey to use for encryption.- Parameters:
key- the PublicKey instance to use for encryption
-
getUseThisPublicKey
-
getEncryptedKeyElement
- Returns:
- Returns the encryptedKeyElement.
-
setEncryptedKeyElement
Set the encrypted key element when a pre prepared encrypted key is used- Parameters:
encryptedKeyElement- EncryptedKey element of the encrypted key used
-
getBinarySecurityTokenElement
- Returns:
- Returns the BinarySecurityToken element.
-
setKeyEncAlgo
-
getKeyEncAlgo
-
getKeyAgreementMethod
-
setKeyAgreementMethod
-
getKeyDerivationMethod
-
setKeyDerivationMethod
-
getKeyDerivationParameters
public org.apache.xml.security.encryption.params.KeyDerivationParameters getKeyDerivationParameters() -
setKeyDerivationParameters
public void setKeyDerivationParameters(org.apache.xml.security.encryption.params.KeyDerivationParameters keyDerivationParameters) -
getBSTTokenId
Get the id of the BSt generated duringprepare().- Returns:
- Returns the the value of wsu:Id attribute of the BinaruSecurityToken element.
-
setEncKeyId
- Parameters:
encKeyId- The encKeyId to set.
-
isCertSet
public boolean isCertSet() -
setCustomEKTokenValueType
-
setCustomEKTokenId
-
setDigestAlgorithm
Set the digest algorithm to use with the RSA-OAEP key transport algorithm. The default is SHA-1.- Parameters:
digestAlgorithm- the digest algorithm to use with the RSA-OAEP key transport algorithm
-
getDigestAlgorithm
Get the digest algorithm to use with the RSA-OAEP key transport algorithm. The default is SHA-1. -
setMGFAlgorithm
Set the MGF algorithm to use with the RSA-OAEP key transport algorithm. The default is MGF-SHA-1.- Parameters:
mgfAlgorithm- the MGF algorithm to use with the RSA-OAEP key transport algorithm
-
getMGFAlgorithm
Get the MGF algorithm to use with the RSA-OAEP key transport algorithm. The default is MGF-SHA-1. -
isIncludeEncryptionToken
public boolean isIncludeEncryptionToken() -
setIncludeEncryptionToken
public void setIncludeEncryptionToken(boolean includeEncryptionToken) -
getCustomEKKeyInfoElement
-
setCustomEKKeyInfoElement
-
setEncryptedKeySHA1
- Throws:
WSSecurityException
-
getEncryptedKeySHA1
-