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?


closed as off-topic by e-sushi Sep 20 '16 at 13:19

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Programming questions are off-topic even if you are writing or debugging cryptographic code. Unless your question is specifically about how the cryptographic algorithm or protocol works, you should look into asking on Stack Overflow instead." – e-sushi
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 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

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.


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