0

Is there a way to eliminate special characters when encrypting with GnuPG. I got the below issue. When I encrypt some text with GPG it is including special characters like +.

Encrypt Command

--encrypt --armor --recipient

So when this encrypted text is passed via query string and when try to decrypt. I am getting the below error.

Error

gpg: no valid OpenPGP data found.gpg: decrypt_message failed: Unknown system error 

So, Is there a way to configure GPG not to include some special characters?

  • Why not let GnuPG do its job (encryption) and then deal specifically with URL escaping characters when you place them in a URL (no matter what their origin) – Damien_The_Unbeliever May 09 '16 at 09:02
  • You meant to say to use like this ??? `\+` `\\r` `\\n` –  May 09 '16 at 09:03
  • No, I mean use something like [`WebUtility.UrlEncode`](https://msdn.microsoft.com/en-us/library/system.net.webutility.urlencode(v=vs.110).aspx) or the like. Unless you like re-inventing code that has already been well written and tested. – Damien_The_Unbeliever May 09 '16 at 09:06

1 Answers1

0

No, there isn't. OpenPGP specifies two encodings, the ASCII armoring you use and the binary format.

ASCII armoring has originally been developed for mail transfer which only allows the basic, 7-bit ASCII characters without further encoding.

URL encoding requires additional limitations or encoding. If you cannot change the data (and with GnuPG/OpenPGP you can't), you'll have to add another encoding as enforced by the transfer protocol you chose.

Luckily, C# has such URL encoding and decoding methods built-in. I'd propose you also try URL-encoding the binary data if transmission size is critical, this might save a significant portion of data. If you only rarely transmit small encrypted messages, I'd stay with URL encoding the ASCII-armored message, as handling the ASCII-armored string data is generally more robust than exchanging binary information.

Community
  • 1
  • 1
Jens Erat
  • 37,523
  • 16
  • 80
  • 96