einarpersson / simple-pem2jwk

Parse PEM to JWK format without dependencies
3 stars 2 forks source link

Does not seem to work for all PEM keys #1

Open einarpersson opened 5 years ago

einarpersson commented 5 years ago
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuE/FMV5H4pm6UmZL3JLc
/Xc8Quu9ZgDWFROJSbeHjIUoKGa0/nhb38C7ILO7H76F965nuZ8n+peNnd2O3LPq
gP+Ltt811RvurS9a7S7C45eKobVXZz+Y0HqDCecvvZQ4Q/+LWBIrKNpIVT7JVumh
0sm3Inn9tWDIfcbo0CBg39AagXrLG4rxt8ZoCS3LhORKCV4Zjns+XXVJO+E2R9KG
RavjSb+wfvU7QlZkqWryszGRG5pIZ0iz4UsiQzNm3aJwFwoVb5lF1C3IYWc1cfdY
bPHBeI9aaHTrnn47UqXiyZm28krOZ7FnTiXDGV92mlyAPBkxF3iHasoeon7MscSZ
zwIDAQAB
-----END PUBLIC KEY-----
-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC4T8UxXkfimbpS
Zkvcktz9dzxC671mANYVE4lJt4eMhSgoZrT+eFvfwLsgs7sfvoX3rme5nyf6l42d
3Y7cs+qA/4u23zXVG+6tL1rtLsLjl4qhtVdnP5jQeoMJ5y+9lDhD/4tYEiso2khV
PslW6aHSybcief21YMh9xujQIGDf0BqBessbivG3xmgJLcuE5EoJXhmOez5ddUk7
4TZH0oZFq+NJv7B+9TtCVmSpavKzMZEbmkhnSLPhSyJDM2bdonAXChVvmUXULchh
ZzVx91hs8cF4j1podOuefjtSpeLJmbbySs5nsWdOJcMZX3aaXIA8GTEXeIdqyh6i
fsyxxJnPAgMBAAECggEANOZgWK0QwM8SlTfbKjHUz8L7PtHeiHpQ97elvcy5UPGe
9wmThT4SUIRGsTokyRWr6cza5IHzvY7mDJtct6fD9MZj2VbzYnkj5f0jgdPcB+qk
1YjwzyeHur6PAb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PWqJjNX8VQ0
le20XAxGTjMTrZPYo1ZtHYs=
-----END PRIVATE KEY-----

(generated through openssl genpkey -algorithm RSA -out private_key.pem -pkeyopt rsa_keygen_bits:2048 and openssl rsa -pubout -in private_key.pem -out public_key.pem)

einarpersson commented 5 years ago

Probably relates to https://unix.stackexchange.com/questions/415970/openssl-genpkey-algorithm-rsa-vs-genrsa

openssl rsa encloses them in BEGIN RSA PRIVATE KEY and END RSA PRIVATE KEY while openssl genpkey omits the RSA. The former is PKCS#1 format, while the latter is PKCS#8.

So this lib should accept both formats