CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    Dec 2002
    Location
    St.Louis MO, USA
    Posts
    672

    [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.
    A Person who is polite is given goodness and a person who is away from Politeness is away from Goodness.

    NAUMAAN

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: IXMLDOMDocument::load failed if used encrypted characters

    Do you read it using VC++ code? How?
    Victor Nijegorodov

  3. #3
    Join Date
    Dec 2002
    Location
    St.Louis MO, USA
    Posts
    672

    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
    A Person who is polite is given goodness and a person who is away from Politeness is away from Goodness.

    NAUMAAN

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    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.

  5. #5
    Join Date
    Dec 2002
    Location
    St.Louis MO, USA
    Posts
    672

    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, "&",  "&amp;");
        replace_all(*data, "\"", "&quot;");
        replace_all(*data, "\'", "&apos;");
        replace_all(*data, "<",  "&lt;");
        replace_all(*data, ">",  "&gt;");
    }
    if I only use £ character in password even then I cannot load my xml file, and its not an escape character.
    A Person who is polite is given goodness and a person who is away from Politeness is away from Goodness.

    NAUMAAN

  6. #6
    Join Date
    Oct 2002
    Location
    Austria
    Posts
    1,284

    Re: IXMLDOMDocument::load failed if used encrypted characters

    Quote Originally Posted by Naumaan View Post
    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

  7. #7
    Join Date
    Dec 2002
    Location
    St.Louis MO, USA
    Posts
    672

    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.
    A Person who is polite is given goodness and a person who is away from Politeness is away from Goodness.

    NAUMAAN

  8. #8
    Join Date
    Oct 2002
    Location
    Austria
    Posts
    1,284

    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

  9. #9
    Ejaz's Avatar
    Ejaz is offline Elite Member Power Poster
    Join Date
    Jul 2002
    Location
    Lahore, Pakistan
    Posts
    4,211

    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?

  10. #10
    Join Date
    Dec 2002
    Location
    St.Louis MO, USA
    Posts
    672

    Re: IXMLDOMDocument::load failed if used encrypted characters

    Its a requirement from customer.
    A Person who is polite is given goodness and a person who is away from Politeness is away from Goodness.

    NAUMAAN

  11. #11
    Join Date
    Apr 1999
    Posts
    27,449

    Re: IXMLDOMDocument::load failed if used encrypted characters

    Quote Originally Posted by Naumaan View Post
    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
    Last edited by Paul McKenzie; May 7th, 2012 at 12:35 PM.

  12. #12
    Join Date
    Dec 2002
    Location
    St.Louis MO, USA
    Posts
    672

    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.
    A Person who is polite is given goodness and a person who is away from Politeness is away from Goodness.

    NAUMAAN

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured