* Structure to collect encryption requirements.
*/
struct XMLTOOL_API EncryptionParams {
-
/**
* Constructor.
*
}
~EncryptionParams() {}
- private:
+
const XMLCh* m_algorithm;
const unsigned char* m_keyBuffer;
unsigned int m_keyBufferSize;
const xmltooling::Credential* m_credential;
bool m_compact;
-
- friend class Encrypter;
};
/**
* Structure to collect key wrapping/transport requirements.
*/
struct XMLTOOL_API KeyEncryptionParams {
-
/**
* Constructor.
*
}
~KeyEncryptionParams() {}
- private:
+
const xmltooling::Credential& m_credential;
const XMLCh* m_algorithm;
const XMLCh* m_recipient;
-
- friend class Encrypter;
};
Encrypter() : m_cipher(NULL) {}
if (kencParams)
throw EncryptionException("Generating EncryptedKey inline requires the encryption key in raw form.");
}
- else if (!encParams.m_credential) {
+ else {
if (!kencParams)
throw EncryptionException("Using a generated encryption key requires a KeyEncryptionParams object.");
if (!key)
throw EncryptionException("Unable to build wrapper for key, unknown algorithm?");
+ // Overwrite the length if known.
+ switch (static_cast<XSECCryptoSymmetricKey*>(key)->getSymmetricKeyType()) {
+ case XSECCryptoSymmetricKey::KEY_3DES_192:
+ encParams.m_keyBufferSize = 192/8;
+ break;
+ case XSECCryptoSymmetricKey::KEY_AES_128:
+ encParams.m_keyBufferSize = 128/8;
+ break;
+ case XSECCryptoSymmetricKey::KEY_AES_192:
+ encParams.m_keyBufferSize = 192/8;
+ break;
+ case XSECCryptoSymmetricKey::KEY_AES_256:
+ encParams.m_keyBufferSize = 256/8;
+ break;
+ }
// Set the encryption key.
m_cipher->setKey(key);
}
return xmlEncData;
}
-EncryptedKey* Encrypter::encryptKey(const unsigned char* keyBuffer, unsigned int keyBufferSize, KeyEncryptionParams& kencParams, bool compact)
+EncryptedKey* Encrypter::encryptKey(
+ const unsigned char* keyBuffer, unsigned int keyBufferSize, KeyEncryptionParams& kencParams, bool compact
+ )
{
// Get a fresh cipher object and document.