Bonjour les curieuses et les curieux,
Ce sujet aurait pu aussi trouver sa place dans la catégorie "Sécurité".
7z tout le monde connaît cet utilitaire d'Igor Pavlov.
Si non, vous pouvez aller voir à cette adresse : https://www.7-zip.fr/
7z permet de compresser ses fichiers, ses dossiers, un volume.
Il offre la possibilité de chiffrer l'archive avec un mot de passe.
Le chiffrement par défaut est Zipcrypto.
Mais, on peut le chiffrer avec AES256.
Pour chiffrer avec la méthode AES256, dans un terminal, on saisira, par exemple :
7z a -tzip -mem=AES256 -ptoto fichieraes.zip Nom_des_lunes.txt
(source : https://www.dzhang.com/blog/2018/03/11/using-7-zip-create-aes-256-encrypted-zip-files-command-line)
Le terminal renverra ce qui suit :
7-Zip [32] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=fr_FR.UTF-8,Utf16=on,HugeFiles=on,32 bits,1 CPU Intel(R) Celeron(R) M CPU 410 @ 1.46GHz (6E8),ASM)
Scanning the drive:
1 file, 1685 bytes (2 KiB)
Creating archive: fichieraes.zip
Items to compress: 1
Files read from disk: 1
Archive size: 1004 bytes (1 KiB)
Everything is Ok
Attention, cela ne fonctionne pas avec les autres formats de compression différents de .zip.
Ci-dessous, le retour avec les formats .wim et .7z :
# 7z a -twim -mem=AES256 -ptoto fichieraes1.wim Nom_des_lunes.txt
7-Zip [32] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=fr_FR.UTF-8,Utf16=on,HugeFiles=on,32 bits,1 CPU Intel(R) Celeron(R) M CPU 410 @ 1.46GHz (6E8),ASM)
Scanning the drive:
1 file, 1685 bytes (2 KiB)
Creating archive: fichieraes1.wim
Items to compress: 1
System ERROR:
E_INVALIDARG
# 7z a -t7z -mem=AES256 -ptoto fichieraes1.7z Nom_des_lunes.txt
7-Zip [32] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=fr_FR.UTF-8,Utf16=on,HugeFiles=on,32 bits,1 CPU Intel(R) Celeron(R) M CPU 410 @ 1.46GHz (6E8),ASM)
Scanning the drive:
1 file, 1685 bytes (2 KiB)
Creating archive: fichieraes1.7z
Items to compress: 1
System ERROR:
E_INVALIDARG
Le chiffrement avec le commutateur -mem=AES256 autorise un utilisateur lambda à lister le contenu.
Ci-dessous, la preuve par l'essai :
# 7z l fichieraes.zip
7-Zip [32] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=fr_FR.UTF-8,Utf16=on,HugeFiles=on,32 bits,1 CPU Intel(R) Celeron(R) M CPU 410 @ 1.46GHz (6E8),ASM)
Scanning the drive for archives:
1 file, 1004 bytes (1 KiB)
Listing archive: fichieraes.zip
--
Path = fichieraes.zip
Type = zip
Physical Size = 1004
Date Time Attr Size Compressed Name
------------------- ----- ------------ ------------ ------------------------
2025-03-14 23:56:53 ..... 1685 814 Nom_des_lunes.txt
------------------- ----- ------------ ------------ ------------------------
2025-03-14 23:56:53 1685 814 1 files
Cette solution peut être satisfaisante.
Toutefois, on pourrait vouloir interdire à notre utilisateur lambda de connaître le contenu d'un fichier compressé chiffré.
Comment ?
Pour cela, il faut remplacer le commutateur -mem=AES256 par le commutateur -mhe=on.
Il convient de rappeler ici que ce commutateur -mhe ne peut utiliser qu'avec le format de compression .7z.
Voyons ce que cela donne :
# 7z a -mhe=on -ptoto fichieraes1.7z Nom_des_lunes.txt
7-Zip [32] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=fr_FR.UTF-8,Utf16=on,HugeFiles=on,32 bits,1 CPU Intel(R) Celeron(R) M CPU 410 @ 1.46GHz (6E8),ASM)
Scanning the drive:
1 file, 1685 bytes (2 KiB)
Creating archive: fichieraes1.7z
Items to compress: 1
Files read from disk: 1
Archive size: 1064 bytes (2 KiB)
Everything is Ok
# 7z l -slt fichieraes1.7z
7-Zip [32] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=fr_FR.UTF-8,Utf16=on,HugeFiles=on,32 bits,1 CPU Intel(R) Celeron(R) M CPU 410 @ 1.46GHz (6E8),ASM)
Scanning the drive for archives:
1 file, 1064 bytes (2 KiB)
Listing archive: fichieraes1.7z
Enter password (will not be echoed):
Si l'utilisateur lambda ne possède pas le mot de passe, il sera de la revue et devra passer son chemin.
Si l'utilisateur détient le mot de passe, il pourra le saisir à l'aveugle et prendra connaissance du contenu de l'archive compressée chiffrée.
Voyons :
Enter password (will not be echoed):
--
Path = fichieraes1.7z
Type = 7z
Physical Size = 1064
Headers Size = 200
Method = LZMA2:12 7zAES
Solid = -
Blocks = 1
----------
Path = Nom_des_lunes.txt
Size = 1685
Packed Size = 864
Modified = 2025-03-14 23:56:53
Attributes = A_ -rwxrwxrwx
CRC = 8DD040D3
Encrypted = +
Method = LZMA2:12 7zAES:19
Block = 0
La méthode utilisée correspond bien à de l'AES.
Mais que veut dire 7zAES:19 ?
C'est Igor Pavlov qui va nous le dire :
(source : https://sourceforge.net/p/p7zip/patches/25/)
On pourrait vouloir également faire de cette archive auto-extractible afin de pouvoir l'extraire sur un poste où 7z n'est pas installé.
Dans ce cas, on saisira :
# 7z a -mhe=on -sfx -ptoto fichieraes1.7z Nom_des_lunes.txt
7-Zip [32] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=fr_FR.UTF-8,Utf16=on,HugeFiles=on,32 bits,1 CPU Intel(R) Celeron(R) M CPU 410 @ 1.46GHz (6E8),ASM)
Scanning the drive:
1 file, 1685 bytes (2 KiB)
Creating archive: fichieraes2.7z
Items to compress: 1
Write SFX: /usr/lib/p7zip/7zCon.sfx : 513724 bytes (502 KiB)
Files read from disk: 1
Archive size: 514788 bytes (503 KiB)
Everything is Ok
Pour décompresser cette archive auto-extractible, dans un terminal on tapera :
# ./fichieraes2.7z [-o[le_chemin_vers_la_destination]]
7-Zip SFX 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=fr_FR.UTF-8,Utf16=on,HugeFiles=on,32 bits,1 CPU Intel(R) Celeron(R) M CPU 410 @ 1.46GHz (6E8),ASM)
Extracting archive: ./fichieraes2.7z
Enter password (will not be echoed):
--
Path = ./fichieraes2.7z
Type = 7z
Everything is Ok
Je suis certain que vous trouverez des applications avec ces astuces.
Voilà, c'est tout pour aujourd'hui.
Amusez-vous bien !
Amitiés.