by Evan Montgomery-Recht [recht_evan at bah dot com] posted on 2004/06/12 |
|
Tried using the following code to return the rfc822 name, which didn't seem to work.
I added to CERT_AUTHORITY_INFO_ACCESS.cs the
case CERT_ALT_NAME_RFC822_NAME:
this.unionObject = Marshal.PtrToStringAnsi(Marshal.ReadIntPtr(buffer, offset + 4));
break;
thinking that might work. but the problem that I ran into was that
this.dwAltNameChoice = Marshal.ReadInt32(buffer,offset);
was returning a number way to night 851931 or something like that. I expected the code in the CertificateExtensions.cs to be as follows
ext = cert.FindExtension("2.5.29.17");
if (ext != null) { // FindExtension returns a null pointer if the extension could not be found
CERT_ALT_NAME_ENTRY subalt = (CERT_ALT_NAME_ENTRY)Certificate.DecodeExtension(ext, ext.ObjectID, typeof(CERT_ALT_NAME_ENTRY));
Console.WriteLine(subalt.ToString());
}
so instead the hack that I got to work fine is the following...
ext = cert.FindExtension("2.5.29.17");
if (ext != null) {
Encoding ascii = Encoding.ASCII;
char[] asciiChars = new char[ext.EncodedValue.Length-4];
asciiChars = ascii.GetChars(ext.EncodedValue, 4,ext.EncodedValue.Length-4);
string asciiString = new string(asciiChars);
Console.WriteLine(asciiString);
}
any idea's why the sample code isn't working?
Please contact me via email.
thanks,
evan |