daily pastebin goal
34%
SHARE
TWEET

Untitled

a guest Feb 20th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. X509Certificate2 clientCertificate =
  2. this.Request.HttpContext.Connection.ClientCertificate;
  3. X509Chain x509Chain = new X509Chain(){ ChainPolicy = new
  4. X509ChainPolicy({...}};
  5. x509Chain.Build(clientCertificate))
  6. var elements = x509Chain.ChainElements.Cast<X509ChainElement>()
  7. // in elements variable I expect to have more than one item but I don't have
  8.      
  9. Pkcs12Store store = new Pkcs12Store();
  10. X509CertificateEntry[] chain = new X509CertificateEntry[5];
  11.  
  12. X509Certificate cert1 = certParser.ReadCertificate(new
  13. MemoryStream(Encoding.UTF8.GetBytes(certString1)));
  14. X509CertificateEntry certificateEntry1 = new X509CertificateEntry(cert1);
  15. chain[0] = certificateEntry1;
  16. // I adds all certs in order from user cert to root one (self signed)
  17. store.SetKeyEntry(csr.GetCertificationRequestInfo().Subject.ToString(), new
  18. AsymmetricKeyEntry(key.Private), chain);
  19.  
  20. using (var filestream = new FileStream("./full.cert.pfx"), FileMode.Create,
  21. FileAccess.ReadWrite)){
  22. store.Save(filestream, "".ToCharArray(), new SecureRandom());
  23. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top