简体   繁体   中英

Getting “GPG Error” when running Java application as Windows 7 service

When I run my Java application as a Windows service utilizing a wrapper, everything works fine except when the application tries to decrypt a file. It produces the following error:

GPG error >> code: 2 >> gpg: encrypted with RSA key, ID ########
gpg decryption failed: secret key not available.

The application encrypts and decrypts files without any problem when not running as a service. The wrapper also works fine.

Environment variables were set and confirmed in the Windows registry, but for some reason the system doesn't look in the Users\\AppData\\... directory where the key is located.

This is an automated application, so there is no passphrase to encrypt or decrypt files.

What is wrong? Where might the system be looking for a secret key?

I resolved above problem by changing the service properties. Following step I took to resolve the problem.

  1. On command line enter services.msc then hit Enter Key. It will open services window.

  2. Locate my service and right click then click properties

  3. Click on Log on Tab then click on this account radio button

  4. Click on Browse button then Enter the object name to select I entered my username for my machine and click Check Name button once User name confirmed click Ok button

  5. Enter Password and Confirm Password then click Apply click ok notice dialog box

  6. Stop the service then restart the service sends encrypted files and it works as it should be.

Why I have to do this because when I created service by default it is uses Local System account not my user account where all the keys and profile located.

Now question is or someone likes to answer:

How to alter or change Local System account in Windows OS?

Add your keyring to your C:\\Users\\Default\\AppData\\Roaming\\gnupg folder. Apparently the localsystem account grabs the keyring from here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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