- java.lang.Object
-
- org.apache.xml.security.encryption.XMLCipherUtil
-
public final class XMLCipherUtil extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description private static booleangcmUseIvParameterSpecprivate static java.lang.System.LoggerLOG
-
Constructor Summary
Constructors Constructor Description XMLCipherUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static KeyAgreementParametersconstructAgreementParameters(java.lang.String agreementAlgorithmURI, KeyAgreementParameters.ActorType actorType, KeyDerivationParameters keyDerivationParameter, java.security.PrivateKey keyAgreementPrivateKey, java.security.PublicKey keyAgreementPublicKey)Construct an KeyAgreementParameterSpec object from the given parametersstatic java.security.spec.AlgorithmParameterSpecconstructBlockCipherParameters(boolean gcmAlgorithm, byte[] iv)static java.security.spec.AlgorithmParameterSpecconstructBlockCipherParameters(java.lang.String algorithm, byte[] iv)Build anAlgorithmParameterSpecinstance used to initialize aCipherinstance for block cipher encryption and decryption.private static java.security.spec.AlgorithmParameterSpecconstructBlockCipherParametersForGCMAlgorithm(java.lang.String algorithm, byte[] iv)static KeyDerivationParametersconstructKeyDerivationParameter(KeyDerivationMethod keyDerivationMethod, int keyBitLength)Construct a KeyDerivationParameter object from the given keyDerivationMethod data and keyBitLength.static java.security.spec.MGF1ParameterSpecconstructMGF1Parameter(java.lang.String mgh1AlgorithmURI)Create MGF1ParameterSpec for the given algorithm URIstatic javax.crypto.spec.OAEPParameterSpecconstructOAEPParameters(java.lang.String encryptionAlgorithmURI, java.lang.String digestAlgorithmURI, java.lang.String mgfAlgorithmURI, byte[] oaepParams)Method buildOAEPParameters from given parameters and returns OAEPParameterSpec.static KeyAgreementParametersconstructRecipientKeyAgreementParameters(java.lang.String keyWrapAlgoURI, AgreementMethod agreementMethod, java.security.PrivateKey keyAgreementPrivateKey)Construct an KeyAgreementParameterSpec object from the given parametersstatic java.lang.StringgetMgf1URIForParameter(java.security.spec.MGF1ParameterSpec parameterSpec)Get the MGF1 algorithm URI for the given MGF1ParameterSpecstatic byte[]hexStringToByteArray(java.lang.String hexString)Method hexStringToByteArray converts hex string to byte array.
-
-
-
Method Detail
-
constructBlockCipherParameters
public static java.security.spec.AlgorithmParameterSpec constructBlockCipherParameters(java.lang.String algorithm, byte[] iv)Build anAlgorithmParameterSpecinstance used to initialize aCipherinstance for block cipher encryption and decryption.- Parameters:
algorithm- the XML encryption algorithm URIiv- the initialization vector- Returns:
- the newly constructed AlgorithmParameterSpec instance, appropriate for the specified algorithm
-
constructBlockCipherParameters
public static java.security.spec.AlgorithmParameterSpec constructBlockCipherParameters(boolean gcmAlgorithm, byte[] iv)
-
constructBlockCipherParametersForGCMAlgorithm
private static java.security.spec.AlgorithmParameterSpec constructBlockCipherParametersForGCMAlgorithm(java.lang.String algorithm, byte[] iv)
-
constructOAEPParameters
public static javax.crypto.spec.OAEPParameterSpec constructOAEPParameters(java.lang.String encryptionAlgorithmURI, java.lang.String digestAlgorithmURI, java.lang.String mgfAlgorithmURI, byte[] oaepParams)Method buildOAEPParameters from given parameters and returns OAEPParameterSpec. If encryptionAlgorithmURI is not RSA_OAEP or RSA_OAEP_11, null is returned.- Parameters:
encryptionAlgorithmURI- the encryption algorithm URI (RSA_OAEP or RSA_OAEP_11)digestAlgorithmURI- the digest algorithm URImgfAlgorithmURI- the MGF algorithm URI if encryptionAlgorithmURI is RSA_OAEP_11, otherwise parameter is ignoredoaepParams- the OAEP parameters bytes- Returns:
- OAEPParameterSpec or null if encryptionAlgorithmURI is not RSA_OAEP or RSA_OAEP_11
-
constructMGF1Parameter
public static java.security.spec.MGF1ParameterSpec constructMGF1Parameter(java.lang.String mgh1AlgorithmURI)
Create MGF1ParameterSpec for the given algorithm URI- Parameters:
mgh1AlgorithmURI- the algorithm URI. If null or empty, SHA-1 is used as default MGF1 digest algorithm.- Returns:
- the MGF1ParameterSpec for the given algorithm URI
-
getMgf1URIForParameter
public static java.lang.String getMgf1URIForParameter(java.security.spec.MGF1ParameterSpec parameterSpec)
Get the MGF1 algorithm URI for the given MGF1ParameterSpec- Parameters:
parameterSpec- the MGF1ParameterSpec- Returns:
- the MGF1 algorithm URI for the given MGF1ParameterSpec
-
constructRecipientKeyAgreementParameters
public static KeyAgreementParameters constructRecipientKeyAgreementParameters(java.lang.String keyWrapAlgoURI, AgreementMethod agreementMethod, java.security.PrivateKey keyAgreementPrivateKey) throws XMLSecurityException
Construct an KeyAgreementParameterSpec object from the given parameters- Parameters:
keyWrapAlgoURI- key wrap algorithmagreementMethod- agreement methodkeyAgreementPrivateKey- private key to derive the shared secret in case of Diffie-Hellman key agreements- Throws:
XMLSecurityException
-
constructAgreementParameters
public static KeyAgreementParameters constructAgreementParameters(java.lang.String agreementAlgorithmURI, KeyAgreementParameters.ActorType actorType, KeyDerivationParameters keyDerivationParameter, java.security.PrivateKey keyAgreementPrivateKey, java.security.PublicKey keyAgreementPublicKey)
Construct an KeyAgreementParameterSpec object from the given parameters- Parameters:
agreementAlgorithmURI- agreement algorithm URIactorType- the actor type (originator or recipient)keyDerivationParameter- key derivation parameters (e.g. ConcatKDFParams for ConcatKDF key derivation)keyAgreementPrivateKey- private key to derive the shared secret in case of Diffie-Hellman key agreementskeyAgreementPublicKey- public key to derive the shared secret in case of Diffie-Hellman key agreements
-
constructKeyDerivationParameter
public static KeyDerivationParameters constructKeyDerivationParameter(KeyDerivationMethod keyDerivationMethod, int keyBitLength) throws XMLEncryptionException
Construct a KeyDerivationParameter object from the given keyDerivationMethod data and keyBitLength.- Parameters:
keyDerivationMethod- element with the key derivation method datakeyBitLength- expected derived key length in bits- Returns:
- KeyDerivationParameters data
- Throws:
XMLEncryptionException- if KDFParams cannot be created or the KDF URI is not supported or the key derivation parameters are invalid
-
hexStringToByteArray
public static byte[] hexStringToByteArray(java.lang.String hexString)
Method hexStringToByteArray converts hex string to byte array.- Parameters:
hexString- the hex string to convert- Returns:
- the byte array of the input param, empty array if the hex string is empty, or null if input param is null
-
-