makecert comes (for instance) with Visual Studio (it’s deprecated, but still useful).
Open a VS command line (as admin).
Sample command line for a test certificate:
makecert -r -pe -n "CN=localhost" -m 12 -sky exchange -ss myserverCert.cer
- -r: self-signed
- -pe: private key exportable
- -n: Followed by name of publisher’s certificate (“CN=…”)
- -m: duration in months
- -sky: Subject’s key specification (here: Exchange)
- -ss: Name of the subject’s certificate store where the generated certificate will be stored (“my”)
- When copy-pasting, make sure quotes are coped correctly. Don’t use dashes or dots in the CN.
“SSL server mode must use a certificate with the corresponding private key”
Create private key and use X509Certificate2 class instead of X509Certificate:
makecert.exe -r -pe -n "CN=localhost" -sky exchange -sv server.pvk server.cer pvk2pfx -pvk server.pvk -spc server.cer -pfx server.pfx -pi <password> var certificate = new X509Certificate2("path\server.pfx", "password");