Some library allows me to generate a pgp key pair in a such a way:

var options = {
    curve: 'secp256k1',
    userId: 'Hamlet <[email protected]>',
    passphrase: 'To be, or not to be: that is the question',
    material: {
      key: privateKey,
      subkey: privateKey

openpgp.generateKeyPair(options).then(function(keypair) {
    // success
    var privkey = keypair.privateKeyArmored;
    var pubkey = keypair.publicKeyArmored;

That is, given some initial privateKey/material in addition to user_id/passphrase, it generates or perhaps converts into a pgp key.

I wonder, is there a way to do the same things with the standard gpg utility that comes with Linux? I know it accepts userId and passphrase as arguments, but does it accept as an argument something that corresponds to "material" private key in that library?

Or may there a way which include more steps to achieve the same result of generating openpg key pair?

  • What format is the existing key in? Anyway, for properly recreating an existing OpenPGP key, you must also specify the creation timestamp (it is included when calculating the key's fingerprint generally used for identification of a specific key in OpenPGP).
    – Jens Erat
    Commented Oct 21, 2017 at 7:17

1 Answer 1



GNUPG can use an existing key. You need to activate the "expert" option in order to reveal the menu item, if you are using the interactive interface. If you are using GNUPG 2.2.1, you'll see something like this:

$gpg --expert --full-gen-key

gpg (GnuPG) 2.2.1; Copyright (C) 2017 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.

Please select what kind of key you want:
   (1) RSA and RSA (default)
   (2) DSA and Elgamal
   (3) DSA (sign only)
   (4) RSA (sign only)
   (7) DSA (set your own capabilities)
   (8) RSA (set your own capabilities)
   (9) ECC and ECC
  (10) ECC (sign only)
  (11) ECC (set your own capabilities)
  (13) Existing key
Your selection? 

Choose option 13 to use existing PGP key material. You will need to know the keygrip of the starting key. For existing PGP keys working with GPG:

$gpg --with-keygrip --list-secret-keys [keyid]

As far as I understand it, this is a new feature so all the bugs may not be worked out yet... and probably why it's hidden in the "expert" menu. A few simple tests of mine show that it seems to work well with RSA keys, but breaks with Curve 25519 keys.

You must log in to answer this question.

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