Edit I have installed the newest GnuPG for windows (gpg4win 3.1.1)
Which contains the following library versions:
c:\app\security\GnuPG\bin\gpg.exe --version
gpg (GnuPG) 2.2.7
libgcrypt 1.8.2
As for your script it should look the following way
@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 - showing whole workflow (notice that I have the key already there so there is a message, in Czech, that states that the key is without any changes)
My 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
Now the actual workflow:
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>
Edit 3 - To check if the key is imported
c:\app\security\GnuPG\bin\gpg.exe --list-secret-keys --keyid-format LONG
You should get something like this:
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]
Edit 4 - non-interactive batch script:
@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