Say I wanted to encrypt some sensitive information with a symmetric algorithm using a program on a computer. Is it possible that a hacker could retrieve the data,salt, iteration, cipher, keysize while the program is generating ciphered data and after? If possible, how can I prevent this?
Yes, it is possible for an attacker to gain access to your private and sensitive data during encryption or decryption.
This attack is known as memory sniffing attack. In my opinion this is very sophisticated attack. The attacker dump the machine memory (e.g. RAM, swap files, etc) and then analyze this data to retrieve sensitive data (e.g., password, cryptographic keys, etc)
When an attacker is executing this attack on your machine it simply means your machine is already compromised.
How to reduce the risk of this attack? In my opinion, it is all about secure coding practices. In short, make sure when you are implementing your encryption/decryption algorithm that you apply secure coding standard.
You should read more about memory dump attack and secure coding. Several programming languages provide some guidelines and sometimes APIs to reduce the risk of memory dump attack. Here is another article.