Search code examples
javascriptnode.jsopenpgpopenpgp.js

Generating public private keys from openpgp


I have the following code and I'm trying to generate public-private key:

const openpgp = require("openpgp")
const generateKeyPair = async () => {
const { publicKeyArmored } = await openpgp.generateKey({
    userIds: [
        {
            name: 'Jon Smith', email: 'jon@example.com',
            comment: 'This key is for public sharing'
        }
    ],
    curve: 'ed25519',
    passphrase: 'super long and hard to guess secret',
});

console.log(publicKeyArmored);
}

But I'm getting this error. Any idea how to solve it:

(node:17380) UnhandledPromiseRejectionWarning: Error: Unknown option: userIds

Solution

  • publicKeyArmored is not the method of openpgp.generateKey try publicKey.

    const openpgp = require("openpgp")
    const generateKeyPair = async () => {
        const { publicKey } = await openpgp.generateKey({
            curve: 'ed25519',
            userIDs: [
                {
                    name: 'Jon Smith', email: 'jon@example.com',
                    comment: 'This key is for public sharing'
                }
            ],
            passphrase: 'super long and hard to guess secret',
        });
    
        console.log(publicKey);
    }
    
    generateKeyPair()
    

    output ----> enter image description here