Page MenuHome GnuPG

"Invalid option" with utf-16 config files (windows)
Open, NormalPublic


If you create a config file as utf-16 (easy to do unwittingly, e.g. with output
redirection in powershell) then gnupg programs will throw "invalid option".

I discovered this with gpg-agent when trying to add "enable-putty-support" to
gpg-agent.conf. If I edit the file (previously nonexistent) in notepad++, it is
saved by default as ASCII and there is no problem. If I create it using `echo
enable-putty-support > gpg-agent.conf`, then it gets created as utf-16 and is

utf-16 is the default encoding for many programs in Windows. gnupg on Windows
should either parse utf-16, or failing that throw an error clearly stating that
utf-16 config files are not supported.



Event Timeline

Any suggestion on how to detect utf-16 easily?

Werner Koch <> added the comment:

Any suggestion on how to detect utf-16 easily?

Yes, the BOM can be used as a magic number. It will appear either as the byte sequence "0xFF,0xFE", or "0xFE,0xFF", depending on endianness.

It might also be worth detecting UTF8 the same way, by the magic number "0xEF,0xBB,0xBF" - although you may wish to silently drop the magic number and carry on parsing in that case because 7-bit clean UTF8 is often found in the wild and is otherwise identical to ASCII...



It seems that editing a pre-created revocation certificate on Windows with Notepad doesn't let Kleopatra detect this correctly as OpenPGP file and thus refuses to import. Works on the command line but needs more testing.