-
Notifications
You must be signed in to change notification settings - Fork 761
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Binary Serialization of String is still a readable string #799
Comments
Here is a working sample if you wanted to load it up. #include <string.h>
using namespace std;
#include <iostream>
#include "cereal/archives/portable_binary.hpp"
#include "cereal/types/string.hpp"
#include "cereal/external/base64.hpp"
using namespace cereal::base64;
#include <fstream>
class Test
{
public:
Test(string testString, bool humanReadable = true);
template<class Archive>
void serialize(Archive& archive)
{
// serialize things by passing them to the archive
archive(m_testString, x, y, z);
}
private:
string m_testString;
int x;
int y;
int z;
};
Test::Test(string testString, bool humanReadable)
{
m_testString = testString;
x = 12;
y = 35493823;
z = 15;
if (!humanReadable)
{
const char* xx = m_testString.data();
unsigned char* pixels = (unsigned char*)xx;
m_testString = encode(pixels, sizeof(unsigned char) * m_testString.size());
//string dcode = decode(m_testString);
}
}
int main()
{
// human readable
std::ofstream file("reg.bin", std::ofstream::binary | std::ofstream::out | std::ofstream::trunc);
{
cereal::PortableBinaryOutputArchive arb(file);
arb(Test("Helloworld"));
}
// not human readable
std::ofstream fileNHR("regNHR.bin", std::ofstream::binary | std::ofstream::out | std::ofstream::trunc);
{
cereal::PortableBinaryOutputArchive arb(fileNHR);
arb(Test("Helloworld", false));
}
} |
I don't know why you would want BASE64, its not encryption and easily reversible (https://www.base64decode.org/). It not being initially readable does not mean it can't be made readable in no-time, the strings still stand out after writing them out as binary files as BASE64 is easily recognizable. |
Furthermore base64 encoding would take more space than binary encoding. Binary does not mean unreadable, it just means "native representation". It's normal for strings to be readable in binary files, look into the |
Shouldn't you encode the string to base64 so that it is not human readable... similar to when you binary serialize the values of xml in your example here?
https://uscilab.github.io/cereal/serialization_archives.html
XML archives also support explicit binary input/output, which will encode the data as a base64 string:
which will output:
The text was updated successfully, but these errors were encountered: