简体   繁体   English

使用 openssl 循环解密?

[英]Decryption in a loop with openssl?

I'm trying to use openssl to decrypt files.我正在尝试使用 openssl 来解密文件。 I can successfully encrypt them in a loop, but when I try to change the command to make it decrypt, I get "error reading input file."我可以成功地循环加密它们,但是当我尝试更改命令以使其解密时,我得到“读取输入文件时出错”。

for f in /dir1/dir2/*.txt ;
  do [ -f $f ] && openssl aes-256-cbc enc -in $f -out $f.enc -k PASSWORD ;
done

!the above works for encrypting

for f in /dir1/dir2/*.txt.enc ;
  do [ -f $f ] && openssl enc -d -aes-256-cbc -k PASSWORD -in $f -out $f;
done


"error reading input file"

So I've tried making the input file $f.txt.enc, and $f.enc, and similar fiddling with the outfile.因此,我尝试制作输入文件 $f.txt.enc 和 $f.enc,并对输出文件进行类似的摆弄。 No luck.没运气。

I think your encoding line has problem, missing - in front of the aes part... for reference here are lines that work for me:我认为您的编码行有问题,缺少-aes部分前面......供参考,这里有一些对我有用的行:

openssl enc -aes-256-cbc    -in $f      -out $f.enc -k PASSWORD 

openssl enc -aes-256-cbc -d -in $f.enc  -out $f.dec -k PASSWORD

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM