Switch default algorithm to 128-bit since Java is wussy.
[shibboleth/xmltooling.git] / xmltooling / encryption / Encrypter.h
index 3495904..e01803a 100644 (file)
@@ -51,7 +51,10 @@ namespace xmlencryption {
      * Summing up, if KeyEncryptionParams are used, a raw key must be available or the
      * key can be generated when the encryption algorithm itself is a standard one. If
      * no KeyEncryptionParams are supplied, then the key must be supplied either in raw
-     * or object form. 
+     * or object form.
+     *
+     * Finally, when encrypting data, the key transport algorithm can be left blank to
+     * derive it from the data encryption algorithm.
      */
     class XMLTOOL_API Encrypter
     {
@@ -61,7 +64,6 @@ namespace xmlencryption {
          * Structure to collect encryption requirements.
          */
         struct XMLTOOL_API EncryptionParams {
-            
             /**
              * Constructor.
              *
@@ -75,7 +77,7 @@ namespace xmlencryption {
              * @param compact       true iff the encrypted representation should be made as small as possible
              */
             EncryptionParams(
-                const XMLCh* algorithm=DSIGConstants::s_unicodeStrURIAES256_CBC,
+                const XMLCh* algorithm=DSIGConstants::s_unicodeStrURIAES128_CBC,
                 const unsigned char* keyBuffer=NULL,
                 unsigned int keyBufferSize=0,
                 const xmltooling::Credential* credential=NULL,
@@ -85,42 +87,51 @@ namespace xmlencryption {
             }
 
             ~EncryptionParams() {}
-        private:
+
+            /** Data encryption algorithm. */
             const XMLCh* m_algorithm;
+            
+            /** Buffer containing encryption key. */
             const unsigned char* m_keyBuffer;
+
+            /** Size of buffer. */
             unsigned int m_keyBufferSize;
+
+            /** Credential containing the encryption key. */
             const xmltooling::Credential* m_credential;
+
+            /** Flag limiting the size of the encrypted XML representation. */
             bool m_compact;
-            
-            friend class Encrypter;
         };
         
         /**
          * Structure to collect key wrapping/transport requirements.
          */
         struct XMLTOOL_API KeyEncryptionParams {
-            
             /**
              * Constructor.
              * 
              * @param credential    a Credential supplying the key encryption key
-             * @param algorithm     the XML Encryption key wrapping or transport algorithm constant
+             * @param algorithm     XML Encryption key wrapping or transport algorithm constant
              * @param recipient     optional name of recipient of encrypted key
              */
             KeyEncryptionParams(
                 const xmltooling::Credential& credential,
-                const XMLCh* algorithm,
+                const XMLCh* algorithm=NULL,
                 const XMLCh* recipient=NULL
                 ) : m_credential(credential), m_algorithm(algorithm), m_recipient(recipient) {
             }
         
             ~KeyEncryptionParams() {}
-        private:
+
+            /** Credential containing key encryption key. */
             const xmltooling::Credential& m_credential;
+
+            /** Key transport or wrapping algorithm. */
             const XMLCh* m_algorithm;
+
+            /** Name of recipient that owns the key encryption key. */
             const XMLCh* m_recipient;
-            
-            friend class Encrypter;
         };
     
         Encrypter() : m_cipher(NULL) {}
@@ -195,6 +206,15 @@ namespace xmlencryption {
             const unsigned char* keyBuffer, unsigned int keyBufferSize, KeyEncryptionParams& kencParams, bool compact=false
             );
         
+        /**
+         * Maps a data encryption algorithm to an appropriate key transport algorithm to use.
+         * 
+         * @param credential    the key encryption key
+         * @param encryptionAlg data encryption algorithm
+         * @return a key transport algorithm
+         */
+        static const XMLCh* getKeyTransportAlgorithm(const xmltooling::Credential& credential, const XMLCh* encryptionAlg);
+        
     private:
         void checkParams(EncryptionParams& encParams, KeyEncryptionParams* kencParams);
         EncryptedData* decorateAndUnmarshall(EncryptionParams& encParams, KeyEncryptionParams* kencParams);