1

I'm trying to encrypt a string using the openPGP package in golang, but so far I haven't been successful.

Nothing that I've tried so far has worked, so I'm looking for any sort of suggestions or fixes.

The only requirements I have is that it should take the public/private key and the string to decrypt as a string, not files.

I tried to use the examples from this post: http://julianyap.com/2014/07/04/gnu-privacy-guard-gpg-examples-using-golang.html

Specifically this example: https://gist.github.com/jyap808/8324818

But when I run that out of the box it saids the following when trying to read the key

openpgp: invalid argument: no armored data found

And I've found no other good example/working package.

I'm starting to run out of options, as I originally tried to do this in PHP, but failed horribly there too. Would be great if anyone could offer some suggestions!

Thanks in advance

user2578535
  • 148
  • 2
  • 8
  • 1
    If I recall, with gpg `armor` instructs the system to use the special ASCII form of the keys. Update your question with the relevant code around how you are using armor and how you generated the keys (with the `--armor` option, right?). – eduncan911 May 12 '16 at 12:15
  • I'm using the actual example, not changing anything of it. So i'm guessing it should work, but I'll try to generate a key using the armor option. – user2578535 May 12 '16 at 12:28
  • Okey, so I am successfully able to generate messages using my own key, but, I can't decrypt them using any online service that I've tried, it simply will not work. I'm guessing it's because I need certain PGP headers, but I'm unsure what to use for this specifically. Tried just copying some generic ones but it wouldn't work. – user2578535 May 12 '16 at 12:43
  • Are you using the public key to encrypt and the private one to decrypt? – Topo May 12 '16 at 20:06
  • lol I feel almost attacked here, thinking I'm a noob, although I understand it's to rule out the issues one by one. Yes, public key to encrypt and private key to decrypt, however the string returned doesn't have headers so I tried pasting generic ones just to be able to decrypt it, but alas no success – user2578535 May 13 '16 at 11:10

1 Answers1

1

Here's a PGP package for Golang that abstracts away most of the complications and is pretty easy to use:

https://github.com/jchavannes/go-pgp

Checkout the test file for an example:

https://github.com/jchavannes/go-pgp/blob/master/pgp/encrypt_test.go

jchavannes
  • 2,440
  • 1
  • 26
  • 15
  • Thanks for the response, this will come up handy! Waiting on accepting the answer until I've tested out the package – user2578535 Nov 23 '17 at 10:37
  • Cool! I recently used it for something else which it didn't work for. It assumes a lot of default settings which may not apply to all situations. If you run into issues, you may want to dig into the source a bit, it's a pretty thin wrapper. – jchavannes Nov 25 '17 at 08:24