I would like to track log files.
User must only write to log file by using public key and file must be encrypted or user must write to the file which is encrypted by public key before. (User can not edit or read file.)
And, I need to read that log file by using my private key.
Or do you have any suggestions to solve that issue?
An answer has came from Adrian Ho who is Quora User.
- a symmetric stream cipher like ChaCha20 (for text-based logs; if you're writing binary logs in fixed-size blocks, a symmetric block cipher like AES could work too)
- an asymmetric cipher like RSA
Both ciphers should be available in a crypto library for pretty much every production-quality language. I've personally dabbled with both libcrypt (the core library of GnuPG) and NaCl (an alternate crypto library that emphasizes ease-of-use and speed), but go ahead and use whatever you have on hand.
Create an RSA key pair.
Embed the public key in the logger program.
Keep the private key private.
Every time it creates a new log file, it first does the following:
- Generate a new ChaCha20 key at random.
- Encrypt the ChaCha20 key with your RSA public key.
- Write the encrypted ChaCha20 key at the start of the file.
Job done.