I've got the following set of 6 subkeys
$ gpg -K
...
ssb> rsa2048 2017-10-04 [E] [expires: 2027-10-02]
ssb> rsa2048 2017-10-04 [S] [expires: 2027-10-02]
ssb> rsa2048 2017-10-04 [A] [expires: 2027-10-02]
ssb> rsa2048 2015-02-12 [E] [expires: 2025-01-05]
ssb> rsa2048 2016-01-05 [A] [expires: 2026-01-02]
ssb> rsa2048 2016-08-20 [S] [expires: 2026-08-18]
The context is that I bought a new smart card (Yubikey) and generated new subkeys for it. I wanted to keep record of old subkeys in my pubkey so that e.g. Github keeps displaying my old commits signed with old subkeys as "verified".
However I'd like to make sure that from now on only new subkeys are primarly used. e.g. If someone sends me an encrypted message I want them to use the new subkey.
I noticed gpg -e
uses my new encryption subkey by default, so this works as intended, but my question is why?
In other words how does gpg
determine which key to use during encryption? Is it based on order in which subkeys are saved in the file (as above) or creation/expiration date (newer has priority)?