gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-31 01:43:07 24 4
gpt4 key购买 nike

现在我想通过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);

我想在调用 write_xml() 之前加密整个 xml 文件。通过阅读write_xml的代码,我知道xml节点是从ptree中一个一个的读取出来的,然后立即一个一个的写入到fstream中。 有没有办法在将其写入文件之前获取整个 xml 数据流?这样我就可以加密整个数据流,然后将它们写入文件。

目前,我的解决方案是在write_xml创建后重新读取这个xml文件,然后加密xml内容后再写回。

最佳答案

评论者建议:

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

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

现在你可以加密明文并将密文写入文件

关于c++ - 如何通过 boost property_tree 加密 xml 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25785249/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com