openpgpjs/openpgpjs — pull request #65 by toberndo (2013-02-26 18:32:16+00:00)
Title: V4 keys: prefer subkeys for encryption

In the current implementation of openpgp.msg.publickey.getEncryptionKey() the method always returns the primary key if there is a valid and suitable primary key for encryption.

RFC4880 says in 5.5.1.2. Public-Subkey Packet (Tag 14):
```
By convention, the top-level key provides signature services,
and the subkeys provide encryption services
```

Therefore for V4 keys if there exist valid subkeys for encryption they should be also used.
Here also some background on different usage of primary key and subkeys:
http://www.mccune.cc/PGPpage2.htm#Subkeys

I changed the method in a way that for V4 keys first the subkeys are searched and if no valid found only then would the primary key be returned.

The old implementation caused incompatibilities with other PGP implementations (countermail.com) and users also reported that they would like to keep the master key offline on external storage, and only have subkeys available usually.