# NK3 GPG not working

**URL:** https://support.nitrokey.com/t/nk3-gpg-not-working/5082
**Category:** Nitrokeys
**Created:** [May 13, 2023, 3:40pm UTC](https://support.nitrokey.com/t/nk3-gpg-not-working/5082 "2023-05-13T15:40:30Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![sare](https://support.nitrokey.com/letter_avatar_proxy/v4/letter/s/74df32/32.png) [@sare](https://support.nitrokey.com/u/sare)
#### Post date: [May 13, 2023, 3:40pm UTC](https://support.nitrokey.com/t/nk3-gpg-not-working/5082/1 "2023-05-13T15:40:30Z")

</div>

After updating to firmware v1.4.0 I am not able to use pgp keytocard to move a key created outside to the smartcard.

I am not even prompted for the pin anymore. Maybe I entered it wrong multiple times because of I confused gpg pin (which was probably still the default) and the fido2 pin.

```auto
gpg2 --edit-key --expert ...
gpg (GnuPG) 2.2.27; Copyright (C) 2021 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Geheimer Schlüssel ist vorhanden.

sec ed25519/...
     erzeugt: 2023-05-11 verfällt: 2026-05-10 Nutzung: SC  
     Vertrauen: ultimativ Gültigkeit: ultimativ
ssb cv25519/...
     erzeugt: 2023-05-11 verfällt: 2026-05-10 Nutzung: E   
ssb ed25519/...
     erzeugt: 2023-05-11 verfällt: 2026-05-10 Nutzung: A   
[uneingeschränkt] (1). ...

gpg> keytocard
Den Hauptschlüssel wirklich verschieben? (j/N) j
Wählen Sie den Speicherort für den Schlüssel:
   (1) Signatur-Schlüssel
   (3) Authentisierungs-Schlüssel
Ihre Auswahl? 1
gpg: Das KEYTOCARD Kommando schlug fehl: Falsche PIN

gpg> 

```

Now it seems I am even not able to do a factory-reset (gpg2 --card-edit \> admin \> factory reset ).

```auto
gpg2 --card-edit

Reader ...........: 
Application ID ...: 
Application type .: OpenPGP
Version ..........: 3.4
Manufacturer .....: unknown
Serial number ....: 
Name of cardholder: [nicht gesetzt]
Language prefs ...: [nicht gesetzt]
Salutation .......: 
URL of public key : [nicht gesetzt]
Login data .......: [nicht gesetzt]
Signature PIN ....: zwingend
Key attributes ...: ed25519 rsa2048 rsa2048
Max. PIN lengths .: 127 127 127
PIN retry counter : 0 0 0
Signature counter : 0
KDF setting ......: off
Signature key ....: [none]
Encryption key....: [none]
Authentication key: [none]
General key info..: [none]

gpg/card> admin
Admin-Befehle sind erlaubt

gpg/card> factory-reset 
gpg: OpenPGP Karte Nr. ... erkannt

gpg: Hinweis: Dieses Kommando zerstört alle auf der Karte gespeicherten Schlüssel!

Fortsetzen? (j/N) j
Möchten Sie die Karte wirklich komplett löschen? ("yes" eingeben) yes
sending card command SELECT AID failed: Fehlerhafter geheimer Schlüssel

gpg/card> 

```

I am really getting annoyed and losing my trust in nitrokey and the team. The software-development process seems to be not under control. This is extremely critical in such an security-relevant area.

---

<div class="post-metadata">

### Author: ![robin-nitrokey](https://support.nitrokey.com/letter_avatar_proxy/v4/letter/r/b19c9b/32.png) [@robin-nitrokey](https://support.nitrokey.com/u/robin-nitrokey)
#### Post date: [May 16, 2023, 3:44pm UTC](https://support.nitrokey.com/t/nk3-gpg-not-working/5082/2 "2023-05-16T15:44:12Z")

</div>

Unfortunately, there is a bug in GnuPG older than 2.2.35 that affects the factory reset, see:

- [rGf808012ac2cf](https://dev.gnupg.org/rGf808012ac2cf67ec563da178d963f300a7f2564d)
- [Factory Reset fails on old gpg (2.2.21) · Issue #144 · Nitrokey/opcard-rs · GitHub](https://github.com/Nitrokey/opcard-rs/issues/144)

You can fix the problem by updating GnuPG or by using a different application to execute the factory reset, e. g. `openpgp-tool --erase` (from OpenSC) or `opgpcard factory-reset` (from [openpgp-card-tools](https://crates.io/crates/openpgp-card-tools)). We are also working on adding a command to `pynitrokey` to execute the factory reset to work around this issue, see: [Allow resetting opcard-rs · Issue #362 · Nitrokey/pynitrokey · GitHub](https://github.com/Nitrokey/pynitrokey/issues/362)

---

<div class="post-metadata">

### Author: ![sare](https://support.nitrokey.com/letter_avatar_proxy/v4/letter/s/74df32/32.png) [@sare](https://support.nitrokey.com/u/sare)
#### Post date: [May 18, 2023, 6:44am UTC](https://support.nitrokey.com/t/nk3-gpg-not-working/5082/3 "2023-05-18T06:44:17Z")

</div>

Thank you for the solution! With opengpg-tool I was able to do a factory-reset. After that the import of the keys generated outside the nitrokey was successful and now finally after years the gpg encryption with nitrokey3 works as expected.
