I am currently working on a cli application which uses AES encryption. For key generation, I am using the PBKDF-2 algorithm, along with SHA-256. I am providing a way to enter the password once and store the key, to enable the user to use the application multiple times without entering the password, till he decides to remove the key and the password needs to be provided again.
I am currently storing the key in a file, and deleting it once the user decides he is done. I believe this is insecure, as other processes may use that file, and that furthermore, deleting files doesn't really delete the data in them.
What is the best way to solve the above problem? One way is to run the process on a loop, removing the need for password storage, but I want to know if there is a way to securely keep the key across processes.