# Simple encrypt and decrypt folder



## bigart (Feb 22, 2021)

Hi,
I have *test* directory with one file inside *test.txt* and I want to encrypt it and compress

Encrypt and compress command below:

tar cfz - test | openssl enc -aes-256-cbc -a -k test  -salt > test.tar.gz

It's creating file but i can't decrypt it.
How unpack it in one command ?


----------



## DutchDaemon (Feb 22, 2021)

OpenSSL Encrypted Tar Backups for UNIX-like's (Example)
					

A protip by pentago about linux, backup, unix, encryption, freebsd, and tar.



					coderwall.com


----------



## DutchDaemon (Feb 22, 2021)

In other words, you forgot '-e' and maybe the counterpart '-d'.


----------



## bigart (Feb 23, 2021)

encrypt:
`tar cfz - test | openssl enc -aes-256-cbc -e -a -k test -salt > test.tar.gz`

decrypt:
`openssl enc -d -aes-256-cbc -a -k test -in test.tar.gz | tar zxf -`

decrypt to folder
`openssl enc -d -aes-256-cbc -a -k test -in test.tar.gz | tar zxf - -C test2`

decrypt to folder and remove the specified number of leading path
`openssl enc -d -aes-256-cbc -a -k test -in test.tar.gz | tar vzxf - -C test2 --strip-components 1`


----------

