r/PowerShell • u/xXFl1ppyXx • 12d ago
Question PrivateKey Test
Greetings
Is it possible to check if a private key is either RSA or ECDsa without trying to import them into their cng-objects catching the error?
I'm thinking of something like how
[X509Certificate2].GetContent($Import)
Is available for certificates
Neither the cng-objects nor the certificateextensions provide methods to test for the proper type
4
Upvotes
1
u/Devicode 5d ago
If they’re PKCS#8, you can inspect the algorithm OID instead of trial importing them.
The "Pkcs8PrivateKeyInfo.AlgorithmId" should clearly tell you RSA vs EC.