Closed mcavazotti closed 4 years ago
Let me take a look
I have the same issue. It seems to only appear when using an "external" generated key. When I inject a key which got generated by crypton in my process it is working fine. In my case the keys are generated using NodeJs crypto library. See the following code as example to reproduce key generation:
const crypto = require("crypto");
var { publicKey, privateKey } = crypto.generateKeyPairSync(
'rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'pkcs1',
format: 'pem'
},
privateKeyEncoding: {
type: 'pkcs1',
format: 'pem',
}
});
console.log(privateKey);
I try to import the private key using "RSAPrivateKey.fromPEM", but it is the same error if I strip down the key to be usable with the "fromString" function.
I found a solution which is working for me. In nodejs crypto I have to generate a "rsa-pss" key of type "pkcs8".
const crypto = require("crypto");
var { publicKey, privateKey } = crypto.generateKeyPairSync(
'rsa-pss', {
modulusLength: 4096,
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
}
});
console.log(privateKey.toString());
While digging the issue I found that there are several sub versions of pkcs1 and pointycastle is currently only supporting up to v2.0 and it seems that the newer versions v2.1 and/or v2.2 have breaking changes which prevent the import (https://github.com/PointyCastle/pointycastle/blob/master/tutorials/rsa.md#standards-supported). That is a bit of wild guess, since I have not debugged the ASN1 parsing in detail.
Stacktrace:
Code: