hi I just want to know if there is a way to compress a file with a password, or if there is an example that can help me I searched but did not find anything interesting with which I'm comfortable with, because I don't want to protect with an encryption key I want a password that I can put for example in a variable and use it afterwards
Do you want to use a specific compression format? There are a lot of different formats for storing multiple and/or compressing files of which some support encryption, I guess.
.zip or .rar just a simple example compress a file or a folder for example and the result for example MyFolder.zip with my password password if I want to decompress it after I have to enter my password
I found a zip crate, but it only supports decryption, and no encryption . Depending on how interoperable you want/need to be, you could split up the task: use one crate to create an archive, and another crate to encrypt the data.
Sadly I didn't see a high-level library for this either, or at least, not a widely used one.
On the topic more generally -- I guess there's some secure extensions for secure .zip file encryption now (albeit apparently with licensing issues), but historically zip encryption has been a joke (like, crack it in DOS level). Take care to look into this if you find a zip library; .rar might be the better bet. I'm personally used to treating the two concerns (compression, encryption) separately at the file level, e.g. PGP (gpg) on top of gzip or whatever, but didn't see any great options there either.
can you give us an example how to create and put a password or a key with 7-zip it makes me very happy maybe I will change my decision and I will ver 7-zip