简体   繁体   English

如何通过boost property_tree加密xml文件?

[英]How to encrypt xml file by boost property_tree?

Now I want to generate one encrypted XML file through Boost ptree . 现在,我想通过Boost ptree生成一个加密的XML文件。

    using boost::property_tree::ptree;
    ptree   pt;

    pt.add("License.Unalterable.Signed.Guid", m_Guid);
    pt.add("License.Unalterable.Signed.CustomerId", m_CustomerId);
    pt.add("License.Unalterable.Signed.Name", m_Name);
    pt.add("License.Unalterable.Signed.Version", m_version);

    write_xml(licenseFileName, pt);

I want to encrypt the whole xml file before write_xml() is called. 我想在write_xml()之前加密整个xml文件。 Through reading the codes of write_xml , I know the xml nodes are read from ptree one by one, then write them into fstream immediately one by one. 通过读取write_xml的代码,我知道xml节点是从ptree一对一读取的,然后立即将它们一对一地写入fstream Is there any way to get the whole xml data stream before write it to file? 有什么办法可以在将整个xml数据流写入文件之前获取它? so that I can encrypt the whole data stream, then write them to file. 这样我就可以加密整个数据流,然后将它们写入文件。

Currently, My solution is that reread this xml file after created by write_xml , then write it back after encrypting the xml content. 当前,我的解决方案是由write_xml创建后重新读取此xml文件,然后在加密xml内容后将其写回。

The commenters suggested this: 评论者建议:

std::ostringstream oss;
write_xml(oss, pt);

// now you can encrypt
std::string plain_text = oss.str();

Now you can encrypt the plaintext and write the ciphertext to a file 现在您可以加密明文并将密文写入文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM