c++clinuxlibconfig

Storing crypted data with libconfig


I'm using the libconfig to create an configuration file and one of the fields is a content of a encrypted file. The problem occurs because in the file have some escapes characters that causes a partial storing of the content. What is the best way to store this data to avoid accidental escapes caracter ? Convert to unicode? Any suggestion?


Solution

  • You can use either URL encoding, where each non-ASCII character is encoded as a % character followed by two hex digits, or you case use base64 encoding, where each set of 3 bytes is encoded to 4 ASCII characters (3x8 bits -> 4x6 bits).

    For example, if you have the following bytes:

    00 01 41 31 80 FE
    

    You can URL encode it as follows:

    %00%01A1%80%FE
    

    Or you can base64 encode it like this, with 0-25 = A-Z, 26-51 = a-z, 52-62 = 0-9, 62 = ., 63 = /:

    (00000000 00000001 01000001) (00110001 10000000 11111110) -->
    (000000 000000 000101 000001) (001100 011000 000011 111110) 
    
    AAJBNYD.