I have a basic understanding of private/public key cryptography and have been using it for SSH logins and GPG encryption/signing for a while now. However, I have always kept the private key/keyrings in the default location, in my home directory (.gnupg and .ssh). Obviously, I can transfer the keys to a usb drive, which theoretically means neither a keylogger on my computer or the usb drive alone will be enough to get at my private key.

What benefits do smart cards capable of storing private keys, and devices like the YubiKey Neo (which seems to be a smart card + usb reader in a single dongle) offer above storing private keys on a plain-old usb thumb drive?

Does the smart card ever "reveal" the private key to applications like SSH or GPG? If so, it seems anyone who has the PIN and the device itself can still get at the private key, and offers no advantages over regular USB drives. If not, how exactly do applications work without knowing the private key?

  • 1
    Even though a keylogger won't be enough alone to unlock your private key, more advanced malware can still MITM your SSH connection anyway, by providing a fake ssh binary which directly intercepts the data before it is encrypted and sent, or after it is decrypted coming back. Nov 15, 2015 at 16:59

3 Answers 3


Does the smart card ever "reveal" the private key to applications like SSH or GPG? If so, it seems anyone who has the PIN and the device itself can still get at the private key, and offers no advantages over regular USB drives. If not, how exactly do applications work without knowing the private key?

Ideally, No.

The primary advantage of such a token is that it keeps its key secret, and performs crypto activity (such as decrypting, signing, etc.) on the hardware device itself, never disclosing the private key.

So, for example, you can request the public key from the device, and use that public key to encrypt a file (with or without the device present). But to decrypt the file, you have to plug in the token and ask it to decrypt the file for you.

The actual implementation details vary between devices, but this is the general idea of what you want to happen.

Additionally, these crypto tokens often employ some physical security measures to help prevent an attacker from disassembling the device and directly retrieving the key. It's not possible to protect with 100% certainty, but measures like using a single chip design (instead of including a discreet memory chip) and generous helpings of epoxy are common.


OpenPGP smartcards do not reveal your secret keys. Basic signing and decryption tasks are performed by the card's built-in crypto processor, and are only available after entering your PIN code.

Imagine your OpenPGP client (for example, GnuPG) sends a request "decrypt this cypher block" which then is performed by the card (the actual encryption is done using a block cypher which is much faster, and on the computer's CPU), or "sign this user ID of this key", which is again performed by the card.

If the key was generated on the card, it will never leave the card. Alternatively, keys can be generated on your computer and uploaded to the card -- they will not leave the card again, but might be extracted from the computer they've been created on.

Thumb drives store the whole key which can be accessed. If it is attached to your computer, the private keys can be downloaded from it.

  • 3
    1. Does your answer refer to just OpenPGP cards, all smart cards capable of doing PK encryption? 2. Do you mean "decrypt this block cypher key", after which the actual symmetric crypto is done on the host? 3. How does a tiny, inexpensive device like a smart card do the supposedly computation-intensive math required for PK crypto efficiently? Jul 14, 2013 at 9:21
  • I don't know about other smartcards than the OpenPGP ones. The symmetric crypto is done on the host, yes. The current smartcards - as far as I know - are limited to 2k RSA keys for which the math isn't too expensive, especially not if a somewhat specialized processor is used. But regarding the hardware stuff others probably can tell much more.
    – Jens Erat
    Jul 14, 2013 at 9:29
  • 2
    I don't think that the OpenPGP cards allow you to download the private key at all, not even with the admin PIN. The fact that you can get a backup file when you generate a key "on-card" may seem to imply that it should be possible, but if I'm reading the source code right, specifying a backup file just causes GPG to generate the key on the host, save it in the backup file and then upload it to the card. I've skimmed through the card spec, and I don't see any mention of ways to download the private key, neither during generation nor after: g10code.com/docs/openpgp-card-2.1.pdf Jun 14, 2017 at 15:46
  • You're totally right, seems I got this wrong some years ago. I edited the post to contain only correct information.
    – Jens Erat
    Jun 14, 2017 at 20:45

Honestly, it all really depends on the card itself. External security devices for this job typically take one of three forms: store secrets that PC computes on; do all secret storage and computation themselves; something in between. The cards that provide real security do the signing with onboard keys, preferably generated on device too. The idea is the key never leaves the device under any circumstances because the client can't be trusted (i.e. malware).

Using these helps you in two ways:

  1. Malware on PC is reduced to message forgery while the smartcard is insider. Depending on configuration, it might also take customization of the malware reducing your risk even further.

  2. Loosing a smartcard to a thief shouldn't worry you as much as loosing a laptop or USB drive full of secrets.

  3. You can put a smartcard in the wallet you'll likely be carrying anyway.

  4. Quite a few commercial laptops have smartcard readers these days.

One particular feature you should look for is a PIN pad built into the reader. The reason is that this can help you establish a trusted path where your PIN goes directly to smartcard. Without this, you might have entered it into a malware-infested computer via keyboard. A trusted path would have prevented compromises via password/pin of certain "certified," encrypting USB sticks. An example of one with this feature is in the link below. (Along with old links to GPG smart card instructions.)


OpenSSH with smart cards here.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .