I created this private key using node-jose, and then when I load it back into node jose using the asKey function, I get an error;
RangeError: Attempt to access memory outside buffer bounds
const privatePem = `-----BEGIN EC PRIVATE KEY-----
MHcCAQEEIOeCAAAgHeSEY/fn0OYjJh49LKmVReGQmJcQx78u0sVCoAoGCCqGSM49
AwEHoUQDQgAEPwrrzWtZSsEb6EgldGFCnqbykydVPbvtP3H1UKs6EPDCl8mzGMHg
kksAw85JhXLAhy7b4WP0clQCXMDvJGanqg==
-----END EC PRIVATE KEY-----`;
await nodeJose.JWK.asKey(privatePem, 'pem');
This doesn't always happen, more often than not a private key is generated that works completely correctly.
The private key looks valid when I use the command
openssl ec -in broken-pem.pem -noout -text to validate it.
I'm on node v16.14.2 but i've tried it on a lot of different node versions using runkit, and using version 2.2.0 of node-jose.
I'm generating the keys using;
const key = await jose.JWK.createKey('EC', 'P-256', { alg: '' });
const privatePem = key.toPEM(true);
const publicPem = key.toPEM(false);
which creates keys that work 99% of the time.
With the broken key

With a valid key generated in the same way;

This can happen for both public and private keys.