Sometimes you need to send a security certficate with your WebRequest to authenticate with the web service you are accessing, e.g. a REST API via .NET. To authenticate you may need to send a certificate with your web request to authenticate with the API. This guide shows you how to do that using .NET.
First you need to be able to find your certificate. Sometimes it is hard to remember where exactly your certificate is so I have created two methods which together will search all usual locations until it finds the certificate based on its thumbprint.
This bit of code finds and returns the certificate:
//Returns a certificate by searching through all likely places private static X509Certificate2 GetCertificateByThumbprint(string thumbprint) { X509Certificate2 certificate; //foreach likely certificate store name foreach (var name in new[] { StoreName.My, StoreName.Root }) { //foreach store location foreach (var location in new[] {StoreLocation.CurrentUser, StoreLocation.LocalMachine}) { //see if the certificate is in this store name and location certificate = FindThumbprintInStore(thumbprint, name, location); if (certificate != null) { //return the resulting certificate return certificate; } } } //certificate was not found throw new Exception(string.Format("The certificate with thumbprint {0} was not found", thumbprint)); } private static X509Certificate2 FindThumbprintInStore(string thumbprint, StoreName name, StoreLocation location) { //creates the store based on the input name and location e.g. name=My var certStore = new X509Store(name, location); certStore.Open(OpenFlags.ReadOnly); //finds the certificate in question in this store var certCollection = certStore.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, false); certStore.Close(); if (certCollection.Count > 0) { //if it is found return return certCollection[0]; } else { //if the certificate was not found return null return null; } }
With this method created that gets a certificate you can now easily add a certificate to an HttpWebRequest like so:
var request = (HttpWebRequest)HttpWebRequest.Create("https://mysecureapi.com/listofsecrets"); var certificate = GetCertificateByThumbprint("23A43AE81F15CB000000000000000000000000000"); request.ClientCertificates.Add(certificate);Now when you set up the rest of your request and GetResponse you will be sending the certificate also.
Awesome! Great work with this post, i am sure people should have got impressed with this post.
ReplyDeleteGreat Article
DeleteCyber Security Projects Ideas for CSE
Project Centers in Chennai
JavaScript Training in Chennai
JavaScript Training in Chennai
Excellent article. Very interesting to read. I really love to read such a nice article because it is very informative and useful for me. Thanks for nicely sharing.
ReplyDeletehttp://www.graphicdesigningcoursesinlahore.com/
ReplyDeleteMovers and Packers Hyderabad
Movers and Packers Bangalore
Movers and Packers Pune
Movers and Packers Mumbai
Movers and Packers Gurgaon
Movers and Packers Delhi
ReplyDeleteMovers and Packers in Chennai
Movers and Packers in Noida
Movers and Packers in Navi Mumbai
Movers and Packers in Thane
Movers and Packers in Ghaziabad
Movers and Packers in Faridabad
ReplyDeleteMovers and Packers in Mumbai
Movers and Packers in Gurgaon
Movers and Packers in Delhi
Movers and Packers in Hyderabad
ReplyDeleteMovers and Packers in Bangalore
Movers and Packers in Pune
I am very much pleased with the contents you have mentioned. I wanted to thank you for this great article.
ReplyDeleteslitheriounblocked.net slitherioprivateservers.com Clickerheroes2.co
Avriq MAP
ReplyDeleteAvriq
CCTV Camera
Pest control services
PC Optimization
CP Plus
Termite control services
I am very happy to read this. Very interesting! Thanks you . You have posted a trust worthy blog keep sharing
ReplyDeleteHyundai Xcent Double Din Player
Tata Nexon Double Din Player
Hyundai Verna
Hypersonic OEM Double Din Player
J3l USB Double Din Player
Double Din DVD Player
car accessories
Hyundai Creta OEM Double Din Player
Hyundai i20 OEM Double Din Player
Hyundai Grand i10 OEM Double Din Player
Prospectus Patrachar Vidyalaya
ReplyDeleteCBSE Forms
CBSE Patrachar Delhi
Patrachar Vidyalaya phone no.
Motifz Designer Lawn. 1, 2 & 3 Piece Unstitched Premium Embroidered Lawn 2019, Premium Lawn, Lawn 2019, Best lawn collection, Motifz, Best Lawn in Pakistan, Shipping worldwide. Stitching option available.
ReplyDeleteMost employments today require something like a certificate and once you get that recognition, your choices are unending! In this way, venture outside of your usual range of familiarity and get your recognition. fake diploma
ReplyDeleteNice post tutuapp
ReplyDeletePackers and Movers Gurgaon Provide Reliable, Safe and Certified Service Provider list, Get Free ***Best Price Quotaition and Compare Charges. ???Hassle free Household Shifting Services, High Quality packing Material, Office Relocation, Car Transportaion, ###Local and Domestic Shifting Service @
ReplyDeletePackers And Movers Gurgaon
Packers and Movers Pune Provide High Quality ***Household Shifting, Home/Office Relocation, Insurance, Packing, Loading, ###Car Transportation Service Pune and High experiences, Top Rated, Safe and Reliable, Best and Secure Packers and Movers Pune Team List. Get ✔✔✔Affordable Rate Charts and Compare Quotation and Save Money and Time @ Packers And Movers Pune
ReplyDeletePackers And Movers Bangalore Local Household Shifting Service, Get Free Best Price Quotes Local Packers and Movers in Bangalore List, Compare Charges, Save Money And Time at
ReplyDeleteLocal Packers And Movers Bangalore
This is really a pleasant and useful, containing all data furthermore greatly affect the new innovation. Much obliged for sharing it @
ReplyDeletePackers And Movers Gurgaon
Packers And Movers Gurgaon to Bangalore
Packers And Movers Gurgaon to Ahmedabad
Packers And Movers Gurgaon to Jaipur
Get Shifting/Relocation Quotation from ###Packers and Movers Delhi. Packers and Movers Delhi 100% Affordable and Reliable ***Household Shifting Services. Compare Transportation Charges and Save Time, Verified and Trusted Packers and Movers in Delhi, Cheap and Safe Local, Domestic House Shifting @ Packers And Movers Delhi
ReplyDeleteWholesale printed custom perfume boxes with the highest quality and affordable prices. Free worldwide Delivery and free Custom Perfume Boxes design.
ReplyDeleteBuy online wholesale printed custom perfume boxes and packaging at easy prices and shipping worldwide, with 24/7 customer support. Get a free custom quote now!!
ReplyDeleteBlackbird packaging provide you with any size, shape design, custom cbd boxes sooner than any other packaging competitor in the market
ReplyDeletemylar label bags in stock now. Ready made Cali pack designs. Fast Shipping at Your Supplies. Custom designs available
ReplyDeleteBlackbird packaging provide you with any size, shape design, cookie boxes wholesale sooner than any other packaging competitor in the market
ReplyDeleteBlackbird packaging provide you with any size, shape design, custom wholesale cookie boxes sooner than any other packaging competitor in the market
ReplyDeletecali spliff, available at Your Supplies. Cali Pack Heat sealable. Fast Shipping.
ReplyDeletecustom printed printed mylar bags uk in stock now. Ready made Cali pack designs. Fast Shipping at Your Supplies. Custom designs available
ReplyDeleteVery Good way of attracting your reader's attention is to write blog like you. Please do contact me on genuinehotelescorts@gmail.com for
ReplyDeleteJaipur Call Girls
Jaipur Call Girls
Jaipur Call Girls
Delhi Call Girls
Guwahati Call Girls
Guwahati Call Girls
Guwahati Call Girls
Guwahati Call Girls
Aerocity Call Girls
Lucknow Call Girls
Packaging town is a one stop solution for the short-run custom apparel packaging needs and supplies. At affordable prices. Request a free quote now.
ReplyDeleteBlackbird packaging provide you with any size, shape design, bath bomb boxes sooner than any other packaging competitor in the market
ReplyDeleteInteresting article! Thank you for sharing them! I hope you will continue to have similar posts to share with everyone! I believe a lot of people will be surprised to read this article!
ReplyDeleteLove back Solution Specialist
Vashikaran specialist
Love Vashikaran Specialist
Vashikaran Specialist in Chennai Vashikaran Specialist in Jaipur Vashikaran Specialist in Karnataka Vashikaran Specialist in London UK Vashikaran Specialist in Dubai Vashikaran Specialist in Australia Vashikaran Specialist in Punjab