News  [SoftwareSite

Latest News
Older News
RSS Feed
 
Complete Projects
Useful Classes
Top Downloads
Message Board
AllAPI.net
 
Send Comments
Software License
Mentalis.org Buttons
Donate
 
Forums -> Security Library Forum
 
Which country's certificate?  
by LEMBAS [lembas at myway dot com]
posted on 2003/12/18

I want to get the country value in the certificate. i know the oid is 2.5.4.6. I want to search according to 2.5.4.6 and get the value (for example: "uk" or "usa" as string).

//I set the value to null, because that value is the value that i want to get
NameAttribute na = new NameAttribute("2.5.4.6",null);
int i = cert.GetDistinguishedName().IndexOf(na);
Console.WriteLine(cert.GetDistinguishedName()[i].Value);

but i always get i==-1.

how can I get the value of C or CN or L or the others...?

by Pieter Philippaerts [Pieter at mentalis dot org]
posted on 2003/12/18

This is probably what you're looking for:

NameAttribute countryName = new NameAttribute("2.5.4.6", null);
DistinguishedName dn = cert.GetDistinguishedName();
for (int i = 0; i < dn.Count; i++) {
if (dn[i].ObjectID.Equals("2.5.4.6")) {
countryName = dn[i];
break;
}
}
if (countryName.Value == null) {
Console.WriteLine("The country name attribute was not present in the certificate.");
} else {
Console.WriteLine("Country name: " + countryName.Value);
}

by LEMBAS [lembas at myway dot com]
posted on 2003/12/19

I thought I could do it with dn.IndexOf() method. Yours is simpler. Thank you for such a quick & complete response.

 

Copyright © 2002-2007, The Mentalis.org Team. All rights reserved.
This site is located at http://www.mentalis.org/
Send comments to the webmaster.