我有以下脚本。
echo off
cd C:\Users\User_Name\Desktop\Encryption\Hemant test
"C:\Program Files (x86)\GnuPG\bin\gpg.exe" --import PB_Key.gpg
"C:\Program Files (x86)\GnuPG\bin\gpg.exe" -e Test.txt
但是在命令窗口之后,它按照以下要求我输入用户输入 “输入用户ID。末尾用空行:”
如图所示:
我必须传递'Test'值并单击enter。
但我无法在上面的批处理脚本中传递'Test'值。
答案 0 :(得分:0)
修改我已经为Windows安装了最新的GnuPG(gpg4win 3.1.1)
其中包含以下库版本:
c:\app\security\GnuPG\bin\gpg.exe --version
gpg (GnuPG) 2.2.7
libgcrypt 1.8.2
至于你的脚本,它应该采用以下方式
@echo off
cd "C:\Users\User_Name\Desktop\Encryption\Hemant test"
"C:\Program Files (x86)\GnuPG\bin\gpg.exe" --import PB_Key.gpg
set /p user_id=Please enter your user id:
"C:\Program Files (x86)\GnuPG\bin\gpg.exe" -r "%user_id%" --encrypt Test.txt
Edit2 - 显示整个工作流程(请注意我已经存在密钥,因此捷克语中有一条消息表明该密钥没有任何更改)
我的test.bat
@echo off
c:\app\security\GnuPG\bin\gpg.exe --import C:\app\security\GnuPG\mygpgkey_pub.gpg
set /p user_id=Please enter your user id:
c:\app\security\GnuPG\bin\gpg.exe -r "%user_id%" -e VERSION
现在的实际工作流程:
C:\app\security\GnuPG>dir *.gpg
Volume in drive C is OSDisk
Volume Serial Number is 6C83-746F
Directory of C:\app\security\GnuPG
17.05.2018 13:55 6 731 mygpgkey_priv.gpg
17.05.2018 13:55 3 181 mygpgkey_pub.gpg
2 File(s) 9 912 bytes
0 Dir(s) 5 941 710 848 bytes free
C:\app\security\GnuPG>test.bat
gpg: klíč B6E8D7336780XXXX: "John Smith <john.smith@usa.net>" beze změn
gpg: Celkový počet zpracovaných klíčů: 1
gpg: beze změn: 1
Please enter your user id:John Smith
C:\app\security\GnuPG>dir *.gpg
Volume in drive C is OSDisk
Volume Serial Number is 6C83-746F
Directory of C:\app\security\GnuPG
17.05.2018 13:55 6 731 mygpgkey_priv.gpg
17.05.2018 13:55 3 181 mygpgkey_pub.gpg
17.05.2018 13:57 609 VERSION.gpg
3 File(s) 10 521 bytes
0 Dir(s) 5 941 673 984 bytes free
C:\app\security\GnuPG>cat VERSION.gpg
☻♀♥VsP┼ĎžI}☺ ˙w▬ďÍ[Łu a↓#ŇÜŔ~>Ö▬ľżŕ↔►►=*Q×♥+Ç$NôCČuy→8Ą' @⌂∟ĘŽ∟'ôż|→↑|Ţ↕ÄĄú4|-b >%ÄXľ♂Ť ŮLŤÍ♫∟"˛2ýś+¸ęęHDF\`+-BţYu˙:|ŽÝÍ♣%☺RďGX┼łŠX%?Łä÷äĘo'Ę|3.Ń<ě°§ó☻ÇKŰ+CăÉĆŚßźE˙Ń?bÔj§ž`<?Ř9c♦§Şś>Éb˛ (ďćžDŹ☻jí6♦§-ßÚŇ~♀"kfďxĺk)˘¨äŰ×▼N÷1 3"}Ä-sžóáe↓x.↓=mĘ?Đ'Á♥{>7c♫SA^I˛uÁi!$Źő/¶ˇ ÇŃyr☺¬+"F-+ílBn¨xŮ«%]"ól5‼ ☺Ë'►JT↓►ď6ÍŤjÍ|ßŃ"@m+/ ¤¶ĆvŐĂwł♦$Ăżçy% OÇŁŔóť¤"öbzB0X;♠˙/ăÁbĽH♦_@♣Ôă☻Ĺ◄Ł♣\▲
Ă♀é&/►Ë⌂RĚ 'Yô'Kô~Á˝H☻'´pBŚp▬q↓<ÎŃn2Ů *í«[ëťh×űŽ♠oˇ'ĎtČw♠ Sč Pń{vPąŻwĘŰ♣š♂♠↑Öĺ?Űc=¨%ÉöÜš▬űüR0¶ŕ[qäXOżOb%ÁóçĹ;áÄ☺ĹńLúŘ?i┼e3Qť┼{T%Ż<ďĚŇP☺~Çbéx{O☺Ä◄uM× -ۤ[┼^♦ëŐ˙Rđť<2]{\^Ö%E<ÄX4a_R*?^Ç►ë‼♠Ň2ŐČě?z.M 1ä▲ąěŞuźăŁ↔÷q+Ŕ#á'
C:\app\security\GnuPG>cat VERSION
gnupg
2.2.7
C:\app\security\GnuPG>
编辑3 - 检查密钥是否已导入
c:\app\security\GnuPG\bin\gpg.exe --list-secret-keys --keyid-format LONG
你应该得到这样的东西:
C:/Users/userID/AppData/Roaming/gnupg/pubring.gpg
---------------------------------------------------
sec rsa4096/B6E8D7336780XXXX 2018-05-17 [SC]
ABEC1158A91C80AF5B716DCCB6E8D7336780XXXX
uid [ absolutní ] John Smith <john.smith@usa.net>
ssb rsa4096/56735087CF9EXXXX 2018-05-17 [E]
编辑4 - 非交互式批处理脚本:
@echo off
set "user_id=John Smith"
cd "C:\Users\User_Name\Desktop\Encryption\Hemant test"
"C:\Program Files (x86)\GnuPG\bin\gpg.exe" --import PB_Key.gpg
"C:\Program Files (x86)\GnuPG\bin\gpg.exe" -r "%user_id%" --encrypt Test.txt