Search code examples
c#query-stringgnupg

Eliminate Special Characters in GnuPG Encryption


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?


Solution

  • 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.