Encrypt XML Elements with X.509 Certificates - c#

I have copy the samples from msdn site:
http://msdn.microsoft.com/en-us/library/ms229744%28v=VS.90%29.aspx
http://msdn.microsoft.com/en-us/library/ms229943%28v=VS.90%29.aspx
I've created a certificate, but when i run the program i have this error in the Decrypt method: "Unable to retrieve the decryption key"
I've read somewhere that there is a bug in this sample because the Encrypt method don't save the decryption key.
The problem is that i don't understand how can i resolve the problem.
Can you help me please?
The crypted Xml obtained is:
![alt text][1]
I suppose the problem is that doesn't exists the keyName.
[1]: http://www.freeimagehosting.net/uploads/8c603c876e.png ""
I've generated the certificate as:
makecert -sk Abc -n "CN=Abc" -sr localmachine -e 06/22/2011 Abc.cer

ok, when i create the certificate i need to use this parameter:
makecert -r -pe -n "CN=XML_ENC_TEST_CERT" -b 01/01/2005 -e 01/01/2012 -sky exchange -ss my cert.cer

Related

how to enable https for owin self-host webapi

I met this error IDX21323 OpenIdConnectProtocolValidationContext.Nonce was nul and per my searching, it required to use https instead of http.
We can follow this document to create a self-host webapi use OWIN, but the base url is http.
So requirement is enable https for the url. Then how to do it?
I had my way below, but I also want to know a normal way for enabling https...
Thanks for any other advice!
Follow this document, I can use makecert.exe to create a self-signed certificate but I don't know why after I followed the doc to add certificate to Trusted Root Certification Authorities, the certificate didn't appear in the list.(Maybe it require a reboot?)
makecert.exe -n "CN=Development CA" -r -sv TempCA.pvk TempCA.cer
makecert.exe -pe -ss My -sr CurrentUser -a sha1 -sky exchange -n "CN=name"
-eku 1.3.6.1.5.5.7.3.2 -sk SignedByCA -ic TempCA.cer -iv TempCA.pvk
But it made me find there's a certificate issued localhost in the list.
I remembered it is generated by Visual Studio. When we use IIS Express to run the web application via Visual Studio, it will generate it for us. So I want to use it for my Owin api. Then I found this answer. It informed me that I don't need to do any changes in my code, I only need to run a netsh command to bind the certificate to the port.
Then this is the document about how to use command to bind the port with certificate.
And this is the command I used. Getting thrumbprint from certificate and generate guid from an online tool.
netsh http add sslcert ipport=0.0.0.0:8099 certhash=5c50eaxxxxxxz29daea9 appid={ad9f5133-25cd-412a-974c-059bbde7cb3e}

Self Sign Certificate and domain

I created a self sign certificate using the following steps:
Create a Root certificate authority
makecert -pe -n "CN=RootCertificate" -ss root -sr LocalMachine -sky signature -r "RootCertificate.cer"
Create an SSL certificate
makecert -pe -n "CN=SSLCertificate" -ss my -sr LocalMachine -sky exchange -eku 1.3.6.1.5.5.7.3.3 -in "RootCertificate" -is root -ir LocalMachine -sp "Microsoft RSA SChannel Cryptographic Provider" -sy 12 SSLCertificate.cer
Confirm RootCertifcate under Trusted Root Certificate, confirm SSLCertificate sits under Personal Certificates.
I exported SSLCertificate into SSLCertificate.pfx file using MMC GUI.
I import SSLCertificate.pfx into a server computer.
I bind this certificate to port 998 using the command:
netsh http add sslcert ipport=0.0.0.0:998 certhash=‎764f3bef8cf4d72c5cd077da5b0efbec1b3830a5 appid={3fc1e120-6d8d-477e-ad09-67d749e65d83}
I have an application that hosts its own HTTP Listner on port 998. I verified it works because I can browse to https://server_ip:998
My question is: This server is currently on its own, what if it is part of the domain, would my step 1 - 6 be enough? In my opinion i think it should be but then again I'm not very familiar with the network side and there is no domain for me to test this out.
I am not using IIS to host but rather it is a C# form application that hosts this HTTP Listener.

Duplicate Fiddler.cer being inserted into certificate store

I have put together a bare-bones test case which literally does nothing but FiddlerApplication.Startup(8877, true, true); and even with this after clearing the personal store of FiddlerRoot.cer, i'm getting a bunch of random FiddlerRoot.cer sometimes as many as 10 instantly being inserted into the current users personal store. Here is a screenshot of what happens when running the test case and refreshing a web page.
Ultimately it causes Fiddler to spam the error below to my log output:
(20/06/2014 00:43:37)[LogString]/Fiddler.CertMaker> Invoking makecert.exe with arguments: -pe -ss my -n "CN=p.midasplayer.com, O=DO_NOT_TRUST, OU=Created by http://www.fiddler2.com" -sky exchange -in DO_NOT_TRUST_FiddlerRoot -is my -eku 1.3.6.1.5.5.7.3.1 -cy end -a sha1 -m 132 -b 06/19/2013
---------------------------------------------------------------------------------------------
(20/06/2014 00:43:37)[LogString]/Fiddler.CertMaker>8-CreateCert(p.midasplayer.com) => (-1)
Results from C:\Users\Spark\AppData\Local\Test\MakeCert.exe -pe -ss my -n "CN=p.midasplayer.com, O=DO_NOT_TRUST, OU=Created by http://www.fiddler2.com" -sky exchange -in DO_NOT_TRUST_FiddlerRoot -is my -eku 1.3.6.1.5.5.7.3.1 -cy end -a sha1 -m 132 -b 06/19/2013
Error: There are more than one matching certificate in the issuer's my cert store
Failed
adding as answer
Please upgrade to the current version of FiddlerCore, which may resolve this problem. Thanks!

How to add digital signature to my project

When I try to run mi compiled application Windows advertises that the APP don't have any signature and asks if I really want to run my app.
I don't know the reason wich causes that but I think to avoid this I need a digital signature, so from the web I followed this steps:
I've created my own cert with the makecert tool from Windows SDK's, following a example with this code:
makecert -r -pe -a sha1 -n "CN=name, E=name#Hotmail.com, C=US" -b 01/01/2013 -e 01/01/2050 -ss My
Then I can see my own certificate in the "Personal" Folder:
Now I've exported the certificate with this command:
certutil -exportPFX -p "Password" my 586a7358ebdce8854def26875f0f38ab "C:\Test.pfx"
But when I opened the signing tab in my project setings and choosed "Select from file...", VS says this:
The selected certificate is not valid for code-signing. Choose another certificate file.
I did bad something? I don't know how to correctly code-sign my project,
maybe I need a ".cer" certificate instead a ".pfx" certificate?
then how I can generate a valid CER certificate?

How to create certificate for SslStream.AuthenticateAsServer()?

I’m trying to write a server application that uses SSL to communicate. After accepting a connection, I believe I have to call SslStream.AuthenticateAsServer. However, this expects a certificate and I do not understand how to create one.
I followed the advice given in the answer to this question:
I ran the following to create a server.pfx file:
makecert.exe -r -pe -n "CN=localhost" -sky exchange -sv server.pvk
server.cer pvk2pfx -pvk server.pvk -spc server.cer -pfx server.pfx
Then I loaded it in code with:
certificate = new X509Certificate2("server.pfx", "password");
However, I did that exactly, and I get a CryptographicException saying “The specified network password is not correct.”, which is patently false because I used the password x, which is very hard to mistype. What am I doing wrong?
How to: Create Your Own Test Certificate

Categories

Resources