【问题标题】:Using expect script for gpg - password decryption - does not work使用期望脚本进行 gpg - 密码解密 - 不起作用
【发布时间】:2011-11-09 06:06:27
【问题描述】:

您好,我对编写脚本还很陌生。我正在尝试使用 gpg 进行密码加密/解密。加密没有问题。对于解密,我正在尝试使用期望脚本将其自动化。 我尝试使用的基本命令是: gpg -o -d <.gpg file with encrypted password>

当我单独运行这个命令时,它会要求输入密码,当我输入它时,它会按预期创建输出文件。输出文件中有密码。

当我使用期望脚本运行此命令以便可以在运行时自动提供密码时,期望不会创建输出文件。

感谢任何帮助。它没有显示任何错误!输出是:

spawn gpg -o /home/gandhipr/passwdfile -d /home/gandhipr/passfile.gpg
gpg: CAST5 encrypted data
Enter passphrase: 

下面是我的期望脚本。

#!/usr/bin/expect
set timeout 1
set passdir [lindex $argv 0]
set passfile [lindex $argv 1]
set passfilegpg [lindex $argv 2]
set passphrase [lindex $argv 3]
spawn gpg -o $passdir$passfile -d $passdir$passfilegpg
expect "Enter passphrase:"
send "$passphrase\n"
exp_internal 1
exit 0;
interact

【问题讨论】:

  • +1:我还没有遇到这个问题,但是这个问题已经很好了,因为它提供了一个快速的方法来完成这个烦人的任务!必须指出的是,这是一种糟糕的安全做法(只需查看/proc/$pid/cmdline 即可清楚地了解密码,会出现什么问题?),但我潜伏在周围,这是最直接的做法。

标签: encryption passwords expect gnupg


【解决方案1】:

在发送命令中使用\r 而不是\n\r 是模拟用户按 Enter 键的回车符。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-14
    • 2020-03-08
    • 1970-01-01
    • 2015-11-28
    • 2015-12-20
    • 1970-01-01
    相关资源
    最近更新 更多