Good day. Spent a day and a half to find a way to create a file so that the user doesn’t have access to it, or he had it, but couldn’t understand what was written in it. Unfortunately, I did not find anything. It is possible to securely encrypt a file with a key only if the key is requested from the user all the time and does not save it at all. Everything else is quite possible to get around. I decided to try to just restrict access to the file. Take Windows with 2 accounts. We run the application with one of them, as a result of this entry in the home directory will create this file. I wanted to restrict access to the file to everyone, moreover, from whose account this file was created. But even here I was expected to fail. I tried something like this
File file = new File(path); Files.setOwner(file.toPath(), () -> System.getProperty("user.name")); System.out.println(file.setReadable(false)); This code should do what I described above, but firstly on line 2 there is an exceptional situation, the reason for which I don’t understand at all, and on line 3, the result should return true, and return false on windows, and on linux everything works ok. .. So it goes. In general, I am at a dead end and I need the option to restrict access to the file. Well, or if you have another idea to solve this problem, I will also ask you to share it, but the file should be stored locally.