dotnetspider.com


 


TutorialsForumResourcesReviewsJobsInterviewVideosCommunitiesProjectsTraining

Subscribe to Subscribers


Online MembersSunitha
Prasad kulkarni
Prabu Thangavelu
chaminda
sravan
cloud
Shesh Kumar Mishra
Gajanan
pavan
Anu George
somasekar
More...




Resources » Code Snippets » Security


Open Certificate Stores Including Certificates in Token


Posted Date:     Category: Security    Rating: 1 out of 5
Author: Member Level: Gold    Points: 18 (Rs 18)


Open Certificate Stores Including Certificates in Token



In My Previous article Mirror Link I have shown how to open a certificate store (Machine certificate store which is displayed in the Internet Explorer.) but the drawback of that code was it can't open the certificates stored in the token. so here is another method which will overcome the drawback stated above. It will open the certificates of the machine store as well as of the tokens.


/// <summary>

/// Opens the Certificate Store of IE including the Certificates in Token

/// </summary>

/// <param name="popupScript">The variable passed to store the reason if function returns false</param>

/// <returns> True if a certificate is selected and false if no certificate is selected</returns>

public Boolean OpenStoreToken(ref string popupScript)

{

x509_2 = null;

//Create and Initilaize a variable of x509Store providing the store name and the store location

X509Store st = new X509Store(StoreName.My, StoreLocation.CurrentUser);

//Create X509Certificate2Collection

X509Certificate2Collection col = new X509Certificate2Collection();

//Create X509Certificate2Collection

X509Certificate2Collection sel = new X509Certificate2Collection();

//Create X509Certificate2Enumerator

X509Certificate2Enumerator en;// =new X509Certificate2Enumerator();

//Open the Store for readonly purpose

st.Open(OpenFlags.ReadOnly);

//set the col i.e. X509Certificate2Collection to the collection of the certificates stored in the IE and the Token

col = st.Certificates;

//set the sel i.e. X509Certificate2Collection which actuly displays a dialog box for selecting an X.509 certificate from a certificate collection.

sel = X509Certificate2UI.SelectFromCollection(col, "Certificates", "Select one to sign", X509SelectionFlag.SingleSelection);

if (sel.Count > 0)

{

en = sel.GetEnumerator();

en.MoveNext();

x509_2 = en.Current;

}

st.Close();

if (x509_2 == null)

{

popupScript = "You didn't select a certificate!!!";

return false;

}

else

{

return true;

}

}







Thanks and Regards
Meetu Choudhary

Reference http://aspnetbymeetu.blogspot.com/2009/06/open-certificate-stores-including.html


Did you like this resource? Share it with your friends and show your love!





Responses to "Open Certificate Stores Including Certificates in Token"
Author: Vinay Singh    03 Sep 2010Member Level: Gold   Points : 1
Hi,

I am getting error with X509Certificate2UI.

Error 1 The name 'X509Certificate2UI' does not exist in the current context D:\Data\Websites\TestWMW\GUI\Cert\GetCert.aspx.cs 48 21 D:\...\GUI\


Can you please how to resolve the issue



Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Next Resource: Open Certificate Stores
    Previous Resource: Accessing the properties of a digital signature
    Return to Resources
    Post New Resource
    Category: Security


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    Certificate store  .  Digital certificate  .  Digital signature  .  Meetu  .  Meetu choudhary  .  

    My Profile

    Active Members
    TodayLast 7 Daysmore...


    Awards & Gifts


    Email subscription
  • .NET Jobs
  • .NET Articles
  • .NET Forums
  • Articles Rss Feeds
    Forum Rss Feeds



    About Us    Trademark Disclaimer    Contact Us    Copyright    Privacy Policy    Terms Of Use    Revenue Sharing sites   Advertise   Talk to Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.