Class AMEncryptionProvider

    • Field Detail

      • keyMap

        protected static Map keyMap
        A static map contains provider id and symmetric keys as key value pairs. Key generation each time is an expensive operation and using the same key for each provider should be okay.
    • Constructor Detail

      • AMEncryptionProvider

        public AMEncryptionProvider()
    • Method Detail

      • encryptAndReplace

        public Document encryptAndReplace​(Document doc,
                                          Element element,
                                          String secretKeyAlg,
                                          int keyStrength,
                                          String certAlias,
                                          int kekStrength)
                                   throws EncryptionException
        Encrypts the given XML element in a given XML Context document.
        Specified by:
        encryptAndReplace in interface EncryptionProvider
        Parameters:
        doc - the context XML Document.
        element - Element to be encrypted.
        secretKeyAlg - Encryption Key Algorithm.
        keyStrength - Encryption Key Strength.
        certAlias - KeyEncryption Key cert alias.
        kekStrength - Key Encryption Key Strength.
        Returns:
        org.w3c.dom.Document XML Document replaced with encrypted data for a given XML element.
        Throws:
        EncryptionException
      • encryptAndReplace

        public Document encryptAndReplace​(Document doc,
                                          Element element,
                                          String secretKeyAlg,
                                          int keyStrength,
                                          String certAlias,
                                          int kekStrength,
                                          String providerID)
                                   throws EncryptionException
        Encrypts the given XML element in a given XML Context document.
        Specified by:
        encryptAndReplace in interface EncryptionProvider
        Parameters:
        doc - the context XML Document.
        element - Element to be encrypted.
        secretKeyAlg - Encryption Key Algorithm.
        keyStrength - Encryption Key Strength.
        certAlias - KeyEncryption Key cert alias.
        kekStrength - Key Encryption Key Strength,
        providerID - Provider ID.
        Returns:
        org.w3c.dom.Document XML Document replaced with encrypted data for a given XML element.
        Throws:
        EncryptionException
      • encryptAndReplaceResourceID

        public Document encryptAndReplaceResourceID​(Document doc,
                                                    Element element,
                                                    String secretKeyAlg,
                                                    int keyStrength,
                                                    String certAlias,
                                                    int kekStrength,
                                                    String providerID)
                                             throws EncryptionException
        Encrypts the given ResourceID XML element in a given XML Context document.
        Specified by:
        encryptAndReplaceResourceID in interface EncryptionProvider
        Parameters:
        doc - the context XML Document.
        element - Element to be encrypted.
        secretKeyAlg - Encryption Key Algorithm.
        keyStrength - Encryption Key Strength.
        certAlias - KeyEncryption Key cert alias.
        kekStrength - Key Encryption Key Strength,
        providerID - Provider ID.
        Returns:
        org.w3c.dom.Document EncryptedResourceID XML Document.
        Throws:
        EncryptionException
      • encryptAndReplace

        public Document encryptAndReplace​(Document doc,
                                          Element element,
                                          String secretKeyAlg,
                                          int keyStrength,
                                          Key kek,
                                          int kekStrength,
                                          String providerID)
                                   throws EncryptionException
        Encrypts the given XML element in a given XML Context document.
        Specified by:
        encryptAndReplace in interface EncryptionProvider
        Parameters:
        doc - the context XML Document.
        element - Element to be encrypted.
        secretKeyAlg - Encryption Key Algorithm.
        keyStrength - Encryption Key Strength.
        kek - Key Encryption Key.
        kekStrength - Key Encryption Key Strength,
        providerID - Provider ID
        Returns:
        org.w3c.dom.Document XML Document replaced with encrypted data for a given XML element.
        Throws:
        EncryptionException
      • encryptAndReplaceResourceID

        public Document encryptAndReplaceResourceID​(Document doc,
                                                    Element element,
                                                    String secretKeyAlg,
                                                    int keyStrength,
                                                    Key kek,
                                                    int kekStrength,
                                                    String providerID)
                                             throws EncryptionException
        Encrypts the given XML element in a given XML Context document.
        Specified by:
        encryptAndReplaceResourceID in interface EncryptionProvider
        Parameters:
        doc - the context XML Document.
        element - Element to be encrypted.
        secretKeyAlg - Encryption Key Algorithm.
        keyStrength - Encryption Key Strength.
        kek - Key Encryption Key.
        kekStrength - Key Encryption Key Strength,
        providerID - Provider ID
        Returns:
        org.w3c.dom.Document XML Document replaced with encrypted data for a given XML element.
        Throws:
        EncryptionException
      • encryptAndReplaceWSSElements

        public Document encryptAndReplaceWSSElements​(Document doc,
                                                     Map elmMap,
                                                     String encDataEncAlg,
                                                     int encDataEncAlgStrength,
                                                     String certAlias,
                                                     int kekStrength,
                                                     String tokenType,
                                                     String providerID)
                                              throws EncryptionException
        Encrypts the given WSS XML element in a given XML Context document.
        Specified by:
        encryptAndReplaceWSSElements in interface EncryptionProvider
        Parameters:
        doc - the context XML Document.
        elmMap - Map of (Element, wsu_id) to be encrypted.
        encDataEncAlg - Encryption Key Algorithm.
        encDataEncAlgStrength - Encryption Key Strength.
        certAlias - Key Encryption Key cert alias.
        kekStrength - Key Encryption Key Strength.
        tokenType - Security token type.
        providerID - Provider ID.
        Returns:
        org.w3c.dom.Document XML Document replaced with encrypted data for a given XML element.
        Throws:
        EncryptionException
      • getEncryptionAlgorithm

        protected String getEncryptionAlgorithm​(String algorithm,
                                                int keyStrength)
                                         throws EncryptionException
        Gets the equivalent XML encryption algorithm string for a given algorithm and strength that is published by the provider.
        Throws:
        EncryptionException
      • getPrivateKey

        protected PrivateKey getPrivateKey​(org.apache.xml.security.keys.KeyInfo keyinfo)
        Returns the private key for X509Certificate embedded in the KeyInfo
        Parameters:
        keyinfo - KeyInfo
        Returns:
        a private key for X509Certificate
      • decryptKey

        public Key decryptKey​(Element encryptedKey,
                              String certAlias)
        Decrypt the given encrypted key.
        Specified by:
        decryptKey in interface EncryptionProvider
        Parameters:
        encryptedKey - the encrypted key element
        certAlias - the private key alias
        Returns:
        the key associated with the decrypted key.