bash脚本运行各种openssl密码来解密文件

时间:2015-12-02 14:15:19

标签: linux bash loops

我是Linux和脚本的新手,但我想创建一个运行openssl的脚本来测试各种密码。我知道密码,我知道它是用openssl加密的,但我不知道使用了哪个密码。我一直在通过手动更改密码来尝试这一点,但我认为理解脚本如何做到这一点可能值得一试。 我一直在使用的命令是

openssl bf -d -in file.enc -out file.dcrypt 

这会提示我输入密码。 我有一个文本文件与我希望在一行中尝试的所有密码一起保存。

我想循环操作并通过每个密码查看哪个工作。将变量显示为dcrypt文件名的一部分也是很好的。 是伪代码

start loop n(first line in txt file to eof)
openssl 'n' -d -in file.enc -out file.dcrypt.n (a way to add the password?)
exit eof

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:2)

所以在玩了一个简单的循环后,我想出了这个。这很有效,我对解决方案的直截了当感到非常惊讶。不确定它是否是最好的解决方案,但它确实有效!我可以为我运行的每个脚本更改输出目录,这样我的结果就不会相互覆盖。 Ciphers.txt每行包含一个密码格式

#!/bin/bash
#script to automate openssl testing
while read p; do

openssl $p -d -in encrypted.txt -out test1234/$p.jpg -pass pass:1234
done <ciphers.txt

任何评论或评论都表示赞赏。