makecert.exe to create a certificate for an SslStream
Post your questions regarding programming in C# in here.
5 posts
Page 1 of 1
I know that makecert.exe is just for testing purposes, and to get a real one I have to purchase it. But im only going to do tests with it. So here is the situation:
What is the problem? And how can I create a certificate so I can test my program???
- The client connects to the server and creates an SslStream for secure transfer.
- The server creates an SslStream on the connection so the two can communicate together.
- The client authenticates the server with SslStream.AuthenticateAsClient("store.i3c.be")
- The server tries to authenticate with SslStream.AuthenticateAsServer(new X509Certificate(System.IO.Directory.GetCurrentDirectory() + "\\data\\store.i3c.be.cer")) but fails with a NotSupportedException. The message was "The server mode SSL must use a certificate with the associated private key."
What is the problem? And how can I create a certificate so I can test my program???
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;
Over 30 projects with source code!
Please give reputation to helpful members!
![Image]()
![Image]()
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;
Over 30 projects with source code!
Please give reputation to helpful members!

If you want to create and use your own certificate in an SslStream then there will be a couple of things you need to do first.
On the server system you will need to run this command:
Next you will need to import the certificate into the root of the client's certificate store. On the client's system you can either use the wizard or you can use this command:
On the server system you will need to run this command:
Code: Select all
This will generate a certificate and import it into the current user's personal store (this is so the private key can be accessed).makecert.exe -r -pe -n "CN=hostname" -ss my -sr currentuser -sky exchange C:\authority.cer
Next you will need to import the certificate into the root of the client's certificate store. On the client's system you can either use the wizard or you can use this command:
Code: Select all
Once you have the certificates installed and recognized, you could use something like this for the server:
certmgr.exe -add C:\authority.cer -c -s -r localMachine Root
Code: Select all
The client part would look like this:
'where ss is an SslStream
Dim serverAuthority As X509Certificate2 = New X509Certificate2("authority.cer")
Try
ss.AuthenticateAsServer(serverAuthority)
Catch ex As Exception
MsgBox("server " & ex.Message)
End Try
Code: Select all
Try
ss.AuthenticateAsClient("hostname")
Catch ex As Exception
MsgBox("client " & ex.Message)
End Try
It works perfect cooll; What is the advantages of a purchased cert than a certificate for testing? Doesn't the testing cert work over the Internet and only on the local network?
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;
Over 30 projects with source code!
Please give reputation to helpful members!
![Image]()
![Image]()
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;
Over 30 projects with source code!
Please give reputation to helpful members!

An advantage of purchasing a certificate from an existing authority is that you don't need to install the certificate into the root of each client, it should just work. Another advantage is you don't need to worry about keeping the private key safe.
There are no limits to the use of these generated certificates.
There are no limits to the use of these generated certificates.
Thank you. Keeping the private key save is only on the server side right? Well it might not be a big problem. I can just run certmgr.exe to install the certificate on each new client machine.
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;
Over 30 projects with source code!
Please give reputation to helpful members!
![Image]()
![Image]()
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;
Over 30 projects with source code!
Please give reputation to helpful members!

5 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023