python - Incompatible PGP keys between openpgp.js and pgpy: Error "14 is not a valid HashAlgorithm" - Stack Ov

I'm facing an issue when trying to use PGP keys generated by openpgpjs with pgpy in Python. Specif

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744966071a4603686.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信