Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have set-up Gpg4win on Windows Server 2008 R2 and the website is running .Net 4.5.

I'm using the Starksoft OpenPGP dll.

I've added the required public key to Gpg4win via remote desktop, however when testing in the browser I get the following in the browser:

gpg: [email protected]: skipped: No public key gpg: [stdin]: encryption failed: No public key

I've tested locally on my machine and directly in GPA and Kleopatra on the server and the encryption is working correctly. This leads me to believe that the issue is with the public key being set-up via remote desktop and not being accessible to the application pool or similar.

I've tried copying the pubring.gpg, secring.gpg and trustdb.gpg in to a protected subfolder of the website as suggested somewhere (I forget where now) but this has not worked.

Any ideas how to set-up the public keys to be accessible to the IIS user?

share|improve this question
    
GPG keys contain the email addresses for which they are supposed to work. Maybe the mail address is not (precisely) contained in the public key? In that case you need to use the key ID instead... –  owlstead May 9 '13 at 10:26
    
And, btw, why it writes "EMAIL@EMAIL>COM"? (">" instead of ".") Maybe you have the misprint in your code? –  Nickolay Olshevsky May 9 '13 at 10:37
    
@NickolayOlshevsky - just a typo in example where I was holding shift –  Albofish May 9 '13 at 13:42
1  
@owlstead That wouldn't explain why the key works fine for one user but not another. The issue isn't the key not working, the issue is getting the keychain to work for a different user on the server –  Albofish May 9 '13 at 13:43

2 Answers 2

GnuPG looks for keyrings in user's home directory, and IIS is run by other user, most likely this is the reason. You can specify the exact path to public and secret keyrings via --keyring and --secret-keyring command line switches.

share|improve this answer
    
This was my initial thought, however there is no user directory for application pool users. Those switches aren't available through the Starksoft DLL, or at least I haven't found any way of applying them if they are. –  Albofish May 9 '13 at 13:45
1  
In such case you should contact Starksoft for support. Also, there is a bunch of other OpenPGP libraries for .NET, Google for them. –  Nickolay Olshevsky May 9 '13 at 14:33
up vote 1 down vote accepted

Research

Continued research lead me to this SO question: Gpg encryption over web browser which then lead me down the lines of running it via cmd - Running Command line from an ASPX page, and returning output to page

Solution

  1. Export the required keys somewhere (in this case c:\public.key
  2. Create a page with the following code and execute it

    System.Diagnostics.Process si = new System.Diagnostics.Process();
    si.StartInfo.WorkingDirectory = "c:\\";
    si.StartInfo.UseShellExecute = false;
    si.StartInfo.FileName = "cmd.exe";
    si.StartInfo.Arguments = "gpg --import c:\\public.key";
    si.StartInfo.CreateNoWindow = false;
    si.StartInfo.RedirectStandardInput = true;
    si.StartInfo.RedirectStandardOutput = true;
    si.StartInfo.RedirectStandardError = true;
    si.Start();
    string output = si.StandardOutput.ReadToEnd();
    si.Close();
    
  3. The key now works :)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.