Dav*_*ing 3 security hash privacy
我有一组 IIS 日志文件,我想将其发布以进行研究。
但是,这些包含一些我想匿名的敏感信息,例如:
UserName=XXXX65
Run Code Online (Sandbox Code Playgroud)
我想使用一种保留一些“用户友好”特性的算法来对日志文件进行视觉检查,但它也足够安全,无法/不切实际地导出原始用户名。
我不能只* * 列出所有用户名,因为能够将来自同一用户名的请求跨日志关联起来很重要。
使用 SHA1 散列给了我类似的东西
UserName=AD5CBF0BA0A8646EBDBA6BE1B5DA4FCB1F385D39
Run Code Online (Sandbox Code Playgroud)
这是几乎可用的,
SHA256 给出:
UserName=C9B84EE0DD2EFA53645D5268602E23A9E788903B31BBEB99C03982D9B50AF70C
Run Code Online (Sandbox Code Playgroud)
开始变得太长而无法使用,
UserName=1000:153JkeeGAqtG2UsHX57RBqm3O0DIkXhF:31BBDlQrUqqeyaMo/ikCJAXRC4fFXf82
Run Code Online (Sandbox Code Playgroud)
在我看来,这太长而无法使用。
是否有一种算法可以提供相对较短的单向散列但保持安全/不可逆?
我正在寻找可以用眼睛扫描日志文件,并且仍然注意到用户名相关性的东西。
One way hashes aren't really anonymous. Why? One can easily verify which user corresponds to which hash:
"root" is a user.hash("root") and it turns out the result is foo. You publish logs containing several references to foo.root is a user on your machine. I then apply hash("root") myself and obtain foo. Now I know which logs correspond to "root".So in essence: Hashes are useful when you later want to be able to verify from the published logs that a certain user was the cause of a certain log. Not when the goal is anonymity.
Plus, hashes are difficult to read.
I'd generate random pronounceable strings, and map one to each user name. Then publish the logs using the random strings. Truly anonymous and truly readable.
如何产生随机可发音的字符串?交替的辅音和元音。以下是使用 C 的方法(当然,这只会产生一个随机的 6 个字符的字符串。在处理日志时,您需要更多的逻辑来处理它,例如:将每个用户名映射到一个字符串,确保字符串是唯一的):
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#define NAME_LENGTH 6
#define RAND_CHAR(string) \
( (string)[rand () % strlen (string)])
int main (void)
{
char vowel[] = "aeiou";
char consonant[] = "bcdfghjklmnpqrstvwxyz";
int i;
char rand_name[NAME_LENGTH + 1];
srand (time (NULL));
for (i = 0; i < NAME_LENGTH; i++)
rand_name[i] = (i % 2) ? RAND_CHAR (vowel) : RAND_CHAR (consonant);
rand_name[NAME_LENGTH] = '\0';
printf ("%s\n", rand_name);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这是它为我制作的一些示例:
cemala
gogipa
topeqe
lixate
fasota
rironu
如果您服务的用户数与125 * 21 3相当,则需要生成更长的字符串,并且可能使用分隔符使其易于发音:
杰马拉戈吉帕