admin管理员组

文章数量:1406032

I'm facing an issue when trying to use PGP keys generated by openpgpjs with pgpy in Python. Specifically, I am encountering the following error:

14 is not a valid HashAlgorithm

Here is my openpgpjs key generation :

const fs = require('fs');
const openpgp = require('openpgp');

// Function to generate PGP keys and save them to files
async function generateAndWritePGPKeys() {
    // Generate PGP keys
    const { privateKey, publicKey } = await openpgp.generateKey({
        type: 'rsa',
        rsaBits: 4096,
        userIDs: [{ name: 'John Doe', email: '[email protected]' }],
        passphrase: 'SuperSecurePassphrase123!',
        format: 'armored'

    });

    // Define paths for the files
    const privateKeyPath = './priv1.pgp';
    const publicKeyPath = './pub1.pgp';

    // Write the keys to files
    fs.writeFileSync(privateKeyPath, privateKey.replace(/\r/g, ''));
    fs.writeFileSync(publicKeyPath, publicKey.replace(/\r/g, ''));

    console.log('PGP Keys have been written to files:');
    console.log(`Private Key: ${privateKeyPath}`);
    console.log(`Public Key: ${publicKeyPath}`);
}

// Run the function to generate and write keys
generateAndWritePGPKeys();

Here is my python code :

def loadkey(key_path):
    try:
        key, _ = PGPKey.from_file(key_path)
    except Exception as e:
        print(str(e))
        return None
    return key

本文标签: