Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Managing certificates - installing

Status
Not open for further replies.

haddaway

Programmer
Jul 6, 2005
172
SE
I am trying to automate the install of a certificate with the following two lines:

makecert -pe -n "CN=vc" -ss my -sr LocalMachine -a sha1 -sky -r "vc.cer"
makecert -pe -n "CN=localhost" -ss my -sr LocalMachine -a sha1 -sky exchange -eku 1.3.6.1.5.5.7.3.1 -in "vc" -is my -ir LocalMachine -sp "Microsoft RSA SChannel Cryptographic Provider" -sy 12 "vc.cer"

This works great and I wish I could to this by "code". The problem is that I can't be sure in my install, if the certificate is there or not. When running these lines twice only the first line is being run with success (which makes existing certificate unusable) and the second line return this:

Error: There are more than one matching certificate in the issuer's my cert store

I would like to overwrite existing certificate. Or find a way to delete the old. My knowledge on this subject is very limited. Please help me :)
 
I found a way to delete the old certificates:

Dim certCollection As X509Certificate2Collection
Dim store As New X509Store(StoreName.My, StoreLocation.LocalMachine)
store.Open(OpenFlags.ReadWrite)
certCollection = store.Certificates.Find(X509FindType.FindBySubjectName, "vc", False)

store.RemoveRange(certCollection)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top