Reputation: 650
I have this certificate:
I need read field "RFC822". I use X509Certificate2 class, but this class don't return this information:
StringBuilder sb = new StringBuilder();
X509Certificate2 card = GetCertificate();
sb.AppendLine(card.FriendlyName);
sb.AppendLine(card.GetCertHashString());
sb.AppendLine(card.GetEffectiveDateString());
sb.AppendLine(card.GetExpirationDateString());
sb.AppendLine(card.GetExpirationDateString());
sb.AppendLine(card.GetFormat());
//sb.AppendLine(card.GetIssuerName());
sb.AppendLine(card.GetKeyAlgorithm());
sb.AppendLine(card.GetKeyAlgorithmParametersString());
//sb.AppendLine(card.GetName());
sb.AppendLine(card.GetPublicKeyString());
sb.AppendLine(card.GetRawCertDataString());
sb.AppendLine(card.GetSerialNumberString());
sb.AppendLine(card.HasPrivateKey.ToString());
sb.AppendLine(card.Issuer);
sb.AppendLine(card.IssuerName.Name);
sb.AppendLine(card.SerialNumber);
sb.AppendLine(card.Subject);
sb.AppendLine(card.SubjectName.Name);
sb.AppendLine(card.Thumbprint);
sb.AppendLine(card.Version.ToString());
Can I read RFC822 data from .NET program?
Thanks
Upvotes: 0
Views: 2076
Reputation: 11559
You can get bytes of a Subject Alternative Name extension by
byte[] subjAltName = cert.Extensions["2.5.29.17"].RawData
If you look at these bytes by System.Text.Encoding.UTF8.GetString(subjAltName)
you will see email address. But this byte array actually represents an ASN.1 Sequence structure and needs to be decoded properly. As Eugene stated it may be easier to use a third party library which encapsulates complex ASN.1 stuff if you need some deep information inside a certificate.
Upvotes: 2