Encrypting multiple files with AES256 using tar command

I tried to encrypt some files at once with AES256 ,but it failed. I could encrypt only 1 file at a time,wery bothersome .There are this tar command which can create a single file from several files - but I failed at this - something wrong with the command line . Is there any clearcut command line how to create a single file from many files ? Then after that I can encrypt all those data with AES256 .


[Re-Titled by Moderator]

iMac 24″, macOS 15.2

Posted on Jan 31, 2025 6:28 AM

Reply
Question marked as Top-ranking reply

Posted on Jan 31, 2025 12:09 PM

Here is one approach in the Terminal.


Encrypt a compressed tar file from a folder SVG on the Desktop:

tar --exclude='.DS_Store' -cvzp SVG/ | openssl enc -aes-256-cbc -md md5 -pass pass:foobar > a.bin

file a.bin

a.bin: openssl enc'd data with salted password


Decrypt and expand a.bin in different folder on Desktop as tar contents
cd tar_expanded
openssl enc -d -aes-256-cbc -md md5 -pass pass:foobar -in ../a.bin | tar -xvf -
x SVG/
x SVG/scanwo_ocr.pdf
x SVG/foo_ocr_stripped.pdf
x SVG/foo.pdf


Tested: macOS Sequoia v15.3, M4 Mac Mini Pro

25 replies

Feb 1, 2025 8:45 AM in response to MrHoffman

.dmg files I used before and I failed to open it after sometimes ,it simply refused to open . That File Vault is ok ,I use that too . But I may need to know some other ways to encrypt files too .


(a folder is a directory is a folder), how to understand this ? A folder is a directory in a folder ? Or a folder is also a directory?


I could not find anything on internet how to encrypt , in terminal , with openssl several files at one command ,that is why I cannot post anything useful here ,it is only a waste of time ,it is only a guessing - that it maybe so or not. Over the years I learned ,not to waste my time on stuffs which is not clear to me ,or which I cannot in any way understand .

Or maybe you have an idea how to use the terminal to encrypt several files at once with openssl ? That would be a great help.

Feb 1, 2025 10:50 AM in response to MrHoffman

I do not know what Age is ,but I may prefer to stay in my own Table . Better is to use my own computer and not depend on anything outside software . Yes .dmg files are easy to create ,but they have some defects. Over the years whenever I moved to a new Mac all those .dmg files died after a few months. Then this data protection ? I cannot use my Apple ID on this Mac - horrible developments.


I will just study the CLI and see what is possible or what is not possible.


Is that Age is used on the CLI ? I looked at it ,but understand nothing about it.


Encrypted DMG files can and do work, and are widely used. What command and what errors are you encountering?

I typed the passwords in and it did not opened - it is a right password as Bitwarden newer fails in this respect . Or it simply not opening ,it does not asking for a password at all. But I like .dmg files - wery easy to create them in minute - but how to ensure that they will always open ? What to do ,so that I can keep them always in good condition? Or those keys goes out of validity ? Maybe I most change passwords 1 a year ? Why is so that I cannot open a .dmg file on a new Mac ? I have the same Apple ID ,so I cannot understand what is the fault .

Feb 1, 2025 4:23 PM in response to MrHoffman

It’d be a couple of hours to get a OpenSSL/LibreSSL example tested and working to where I’d be willing to post that code, given what I know of the details and risks involved. And that’s not happening this week.


zip is a compression tool, among its other purposes. tar is a tool I’ve had issues with over the years, particularly with its error handling. If necessarily built in, and not zip or tar, nor DU/hdiutil, I’d likely use cpio as the archive tool.


Disk Utility, hdiutil, and age are the paths I’d take, if not zip.


And I’d want a discussion of the risks and the adversaries for this project beforehand, as all of these — including zip and OpenSSL/LibreSSL — have tradeoffs.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Encrypting multiple files with AES256 using tar command

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.