Convert an input string into an obfuscated non-reversible hash string
#include <sys/slog2.h> int slog2_hash( slog2_hash_expiry_t expiry, const char *input, size_t output_size, char *output_hash );
The slog2_hash() function converts an input string into an obfuscated non-reversible hash string containing only numeric literals. You could use this function to obscure information (e.g., email addresses) that might still be useful to include in logs.
The output string can be any desired length, depending on use. If there are many possible input strings, you can help ensure uniqueness of the hash by using the same length of input and hash strings. This function creates identical hash values for a given input string, even if called multiple times inside the expiry window by any process.
Because this function depends on the random number generator, make sure that /dev/random is running before you start slogger2.
0 on success, or -1 if an error occurred (errno is set).
char loghashstr[10+1]; const char *loghash(const char *str) { if (slog2_hash(SLOG2_HASH_EXPIRY_ONE_MONTH, str, sizeof(loghashstr), loghashstr) == -1) return "<hash failed>"; return loghashstr; }
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | Yes |
Signal handler | Yes |
Thread | Yes |