-2
$\begingroup$

I'm saving a log file in with each line corresponds to a log entry.

For integrity reason I'm adding at the end of each line a SHA256 hash of the previous line.

What is the best separator to use string to separate the log entry from the hash?

$\endgroup$
  • 2
    $\begingroup$ Note that a hash such as SHA-256 only protects against non-malicious changes. To protect it against malicious changes you'd need a MAC or signature. $\endgroup$ – Maarten Bodewes Sep 20 '16 at 11:09
4
$\begingroup$

You don't absolutely need a separator as you know the size of the SHA-256 hash (32 bytes or 64 hexadecimals, for instance). If you really want a separator (because you want to change the hash size later on for instance) then you can use any separator that is not within the hexadecimal or base 64 alphabet, i.e. any character or outside the encoding of the hash.

So use a space (_), or a | or even _|_ for some nice whitespace to keep things readable. You need to look for the separator or hash string starting at the end though, e.g. using a regular expression or some lastIndexOf function. Make sure you raise a warning or error if the hash value has not been set, it could have been stripped off.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.