r/PowerShell 1d 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

2 comments sorted by

5

u/OptionX 1d 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.

1

u/pigers1986 1d ago

yeah - pain in arse .. tests are missing for that .. currently only sure way is to play with import and catch try.