2 * Copyright 2001-2006 Internet2
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 * Methods for encrypting XMLObjects and other data.
23 #if !defined(__xmltooling_decrypter_h__) && !defined(XMLTOOLING_NO_XMLSEC)
24 #define __xmltooling_decrypter_h__
26 #include <xmltooling/encryption/Encryption.h>
27 #include <xmltooling/signature/KeyResolver.h>
29 #include <xsec/enc/XSECCryptoKey.hpp>
30 #include <xsec/xenc/XENCCipher.hpp>
32 namespace xmlencryption {
35 * Wrapper API for XML Decryption functionality.
37 class XMLTOOL_API Decrypter
42 * Resolvers will be deleted when Decrypter is.
44 * @param KEKresolver resolves key decryption key
45 * @param resolver resolves data decryption key
47 Decrypter(xmlsignature::KeyResolver* KEKresolver=NULL, xmlsignature::KeyResolver* resolver=NULL)
48 : m_cipher(NULL), m_resolver(resolver), m_KEKresolver(KEKresolver) {
54 * Replace the current data encryption KeyResolver interface, if any, with a new one.
56 * @param resolver the KeyResolver to attach
58 void setKeyResolver(xmlsignature::KeyResolver* resolver) {
64 * Replace the current key encryption KeyResolver interface, if any, with a new one.
66 * @param resolver the KeyResolver to attach
68 void setKEKResolver(xmlsignature::KeyResolver* resolver) {
70 m_KEKresolver=resolver;
74 * Decrypts the supplied information and returns the resulting as a DOM
75 * fragment owned by the document associated with the marshalled EncryptedData
78 * Note that the DOM nodes will be invalidated once that document
79 * is released. The caller should therefore process the DOM fragment as
80 * required and drop all references to it before that happens. The usual
81 * approach should be to unmarshall the DOM and then release it, or the
82 * DOM can also be imported into a separately owned document.
84 * @param encryptedData the encrypted data to decrypt
85 * @return the decrypted DOM fragment
87 DOMDocumentFragment* decryptData(EncryptedData* encryptedData);
90 * Decrypts the supplied information and returns the resulting key.
91 * The caller is responsible for deleting the key. The algorithm of the
92 * key must be supplied by the caller based on knowledge of the associated
93 * EncryptedData information.
95 * @param encryptedKey the encrypted/wrapped key to decrypt
96 * @param algorithm the algorithm associated with the decrypted key
97 * @return the decrypted key
99 XSECCryptoKey* decryptKey(EncryptedKey* encryptedKey, const XMLCh* algorithm);
102 XENCCipher* m_cipher;
103 xmlsignature::KeyResolver* m_resolver;
104 xmlsignature::KeyResolver* m_KEKresolver;
107 DECL_XMLTOOLING_EXCEPTION(DecryptionException,XMLTOOL_EXCEPTIONAPI(XMLTOOL_API),xmlencryption,xmltooling::XMLToolingException,Exceptions in decryption processing);
111 #endif /* __xmltooling_decrypter_h__ */