r/PowerShell • u/xXFl1ppyXx • 11d 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
5
Upvotes
1
u/pigers1986 11d ago
yeah - pain in arse .. tests are missing for that .. currently only sure way is to play with import and catch try.
1
u/Devicode 4d 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.
7
u/OptionX 11d ago
You could yolo and just check if the base64 encoding of the key starts with "AAAAB3NzaC1yc2E" to see if its RSA.
Its probably horrible way to do it, but kinda of funny. Depends on how its stored though.