Зашифровать файл tar асимметрично

1902
DerMike

Я хочу достичь чего-то вроде

tar -c directory | openssl foo > encrypted_tarfile.dat 

Мне нужен инструмент openssl для использования шифрования с открытым ключом.

Я нашел более ранний вопрос о симметричном шифровании в командной строке (sic!), Которого недостаточно. Я заглянул в справочную страницу openssl (1) и нашел только симметричное шифрование. Действительно ли openssl не поддерживает асимметричное шифрование?

В основном, многие пользователи должны создавать свои зашифрованные tar-файлы и хранить их в центральном месте, но только немногим разрешено их читать.

2

4 ответа на вопрос

3
Jeremy W. Sherman

OpenSSL's asymmetric encryption routines lie under the rsautl subcommand. (In recent versions of OpenSSL, this has been superseded by the pkeyutl command, but the arguments seem to be the same.)

Encrypt a tar file using someone's public key:

openssl rsautl -encrypt -inkey Bob.pub -pubin -in foo.tar -out foo.tar.enc 

They can then decrypt the tar file using their private key:

openssl rsautl -decrypt -inkey Bob -in foo.tar.enc -out foo.tar 

Do note that SSH and SSL use different key formats, so if you want to use an SSH key for the encryption/decryption, you can't just use ~/.ssh/id_rsa.pub as-is.

2
rems

Используйте gpg --encrypt .

С "-r" вы можете передать идентификатор пользователя.

Увидеть

man gpg 
Похоже, DerMike спрашивает, как это сделать через openssl, правда? Jeremy W. Sherman 10 лет назад 1
1
galets

Если вы не хотите устанавливать инфраструктуру gpg и просто хотите зашифровать файл с помощью пары открытого и закрытого ключей, вам может пригодиться следующий инструмент: https://github.com/galets/AsymmetricCrypt . Вам понадобится моно на Linux, чтобы запустить его.

отказ от ответственности: я написал это

1
nponeccop

Here are 2 examples from man openssl:

Send encrypted mail using triple DES: openssl smime -encrypt -in in.txt -from steve@openssl.org \ -to someone@somewhere -subject "Encrypted message" \ -des3 user.pem -out mail.msg Sign and encrypt mail: openssl smime -sign -in ml.txt -signer my.pem -text \ | openssl smime -encrypt -out mail.msg \ -from steve@openssl.org -to someone@somewhere \ -subject "Signed and Encrypted message" -des3 user.pem 

Some confusion comes from the fact that s/mime and des3 are mentioned. But in fact the following happens in the examples above:

  • A fresh random symmetric key is generated
  • The file is encrypted using the symmetric key
  • The symmetric key is encrypted using an asymmetric algorithm with a public key stored in user.pem
  • The encrypted symmetric key, the encrypted file and metadata are put into a standard container

The end result is that in.txt file is encrypted into mail.msg file so only the user having the private key matching user.pem public key can decrypt it.

Похожие вопросы