1
1
12rbah2020-08-25 12:46:00
Programming
12rbah, 2020-08-25 12:46:00

How to properly store the encryption key for desktop applications?

Recently I saw an article https://habr.com/ru/company/globalsign/blog/492970/ (briefly a hack on older versions of team Viewer that stored files with passwords in the registry in encrypted form), and wondered if there was a reliable way to store the encryption key (given that it must be stored locally)?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
W
Wataru, 2020-08-25
@12rbah

The only reliable way is to use the master password. If there is no password, then any encryption method can be reverse engineered and all stored data can be decrypted in the same way as the product itself does. Sometimes you don’t even need to figure it out - you can simply tear out the necessary pieces of code from the product and run it.
And with a password - you need some cryptographically stable kdf- function to convert it into an encryption key and then use at least AES, at least some other encryption algorithm.
The main thing is not to cycle anything cryptographic on your own. Take popular crypto libraries and use standard and modern cryptographic primitives.
Here, however, there is a problem - if the user forgets the master password, then the locally saved data can no longer be obtained. You can somehow encrypt the key obtained from the password via KDF (or even in plain text) and additionally give it to the user to save it on a flash drive and use it to recover the password: if there is no password, then the key from the file is applied, then the data is encrypted with a new key, derived from the new user's password. It is only important to convince the user not to store this file on the same computer. If you see this file in the folder with the program, on the desktop or in "my documents", you should scold the user for neglecting security.
To check that the password is correct, the data must be supplied with some kind of checksum (before encryption).
Everything else is security through obscurity. Doesn't work in the long run.

N
none7, 2020-08-25
@none7

In principle, passwords cannot be stored, neither on disk nor in memory, this does not lead to anything good. Even master passwords can be stolen while they are being entered and processed. But in fairness, the servers store secret keys so that we can connect to them with encryption. They just rely on the privileges of the operating system. But if another program is running with your program's privileges or higher, or an attacker has physical access to your hardware, then they can read all your secrets. But on Windows or Android, this distinction is useless, on the first one the garbage heap is executed with maximum privileges, and on the second the holes are not closed at all and only the freshest hardware is able to store secrets.
Security is a complex of measures and it cannot be ensured by simple actions at the program level.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question