[RESOLVED] IXMLDOMDocument::load failed if used encrypted characters
Hi,
It might be an easy solution, but I need help around this issue.
If I load xml file which contains following text. It failed because I am using encrypted characters in Password.
Code:
<?xml version="1.0" encoding="UTF-8"?>
<CONFIGDATA>
<DATABASE>
<DATABASENAME>Symbol</DATABASENAME>
<PRIMARYSERVER>172.27.15.240</PRIMARYSERVER>
<SECONDARYSERVER>172.27.15.240</SECONDARYSERVER>
<USERNAME>admin</USERNAME>
<PASSWORD>uÉ£ë@Å</PASSWORD>
</DATABASE>
</CONFIGDATA>
If I use a plain text in Password element then I can load same file successfully.
I don't know whats kind of encoding I can use for this file or else needs to be fixed to read encrypted characters.
Thanks.
Re: IXMLDOMDocument::load failed if used encrypted characters
Do you read it using VC++ code? How?
Re: IXMLDOMDocument::load failed if used encrypted characters
Yes I am reading in Visual Studio 2010 VC++.
Following are the main steps while reading xml file.
As I mentioned earlier, I can read this file successfully if I am using plain characters in password.
Code:
MSXML::IXMLDOMDocument2Ptr m_plDomDocument;
HRESULT hr = _plDomDocument.CreateInstance(__uuidof(DOMDocument60));
_bstr_t bstrFileName;
bstrFileName = sFileName.AllocSysString();
variant_t vResult;
vResult = m_plDomDocument->load(bstrFileName);
// vResult failed if I use encrypted password in xml file
Thanks
Re: IXMLDOMDocument::load failed if used encrypted characters
You probably need to html encode the password before storing it in the xml and then decode it after you read the xml.
Re: IXMLDOMDocument::load failed if used encrypted characters
You mean something like this
Code:
void escape(std::string *data)
{
using boost::algorithm::replace_all;
replace_all(*data, "&", "&");
replace_all(*data, "\"", """);
replace_all(*data, "\'", "'");
replace_all(*data, "<", "<");
replace_all(*data, ">", ">");
}
if I only use £ character in password even then I cannot load my xml file, and its not an escape character.
Re: IXMLDOMDocument::load failed if used encrypted characters
Quote:
Originally Posted by
Naumaan
if I only use £ character in password even then I cannot load my xml file, and its not an escape character.
there are many more
see that list
Kurt
Re: IXMLDOMDocument::load failed if used encrypted characters
Thanks Arjay and Zuk.
Its a huge list, it means these characters are not allowed in XML. I cannot code for all these escape characters and my encrypted password can contain any character. Is there any other way to accomplish this task.
Re: IXMLDOMDocument::load failed if used encrypted characters
I would just convert the ascii code of each of the password characters into a hex string.
Kurt
Re: IXMLDOMDocument::load failed if used encrypted characters
I'm just curious to know that why you need to store the password in .xml file?
Re: IXMLDOMDocument::load failed if used encrypted characters
Its a requirement from customer.
Re: IXMLDOMDocument::load failed if used encrypted characters
Quote:
Originally Posted by
Naumaan
Hi,
It might be an easy solution, but I need help around this issue.
If I load xml file which contains following text. It failed because I am using encrypted characters in Password.
That is what encoding such as Base64 and ASCII85 are supposed to do, and that is give you an ASCII equivalent of binary data.
Please google this, as this is how you solve your problem. You don't just place binary data in text-based files like that.
http://en.wikipedia.org/wiki/Base64
Look at the second paragraph, where it describes the usage of Base64 to store complex data in an XML document.
So the steps you should be taking when creating the XML password field:
Code:
Encrypt password -> Base64 encode encrypted password -> Store in XML
The other way around
Code:
Read Base64 XML password -> Base64decode password -> Decrypt password (if it can be decrypted back to original password)
Regards,
Paul McKenzie
Re: IXMLDOMDocument::load failed if used encrypted characters
Thanks Paul, It worked for me. I was thinking it might be an issue with XML encoding (How to insert non-english characters in xml file). but found out that there are lot of escape characters. Thanks.