Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

converting base64 encoded certificate to x509certifcate

2,960 views
Skip to first unread message

awri...@gmail.com

unread,
Mar 20, 2009, 10:25:37 PM3/20/09
to
Using vb.net, 3.5 framework. I have an array, which contains a base64
encoded x509 certificate. I need to convert that to a
x509certificate2 object for later use in my project, but I'm having
problems. Here's what I have.

Dim orgCert As New X509Certificate2()
Dim certbytes As Byte() = Convert.FromBase64String(strOrg(2)) 'this
value in the array contains the cert
orgCert.Import(certbytes)
Console.WriteLine(orgCert.SubjectName)
Console.WriteLine(strOrg(2))

The output for "Console.WriteLine(orgCert.SubjectName)" is simply
"System.Security.Cryptography.X509Certificates.X500DistinguishedName"
instead of the actual SubjectName of the certificate, giving me the
impression that the certificate has somehow gotten mangled.

However, if I take the output of "Console.WriteLine(strOrg(2))" and
copy/paste it to notepad, save as filename.cer, Windows sees it as a
valid certificate. So, what's happening when I try and convert the
base64 encoded string item to a byte array? Any other idea how to do
this? Thanks.

Steve

Joe Kaplan

unread,
Mar 20, 2009, 10:41:04 PM3/20/09
to
What you are doing is working and is fine. You can also use the constructor
that takes a byte() if you like.

You are just being mislead by the lack of a good ToString() override on the
X500DistinguishedName class. If you access the Name property of the class,
that will show you what you expect to see.

--
Joe Kaplan-MS MVP Directory Services Programming
Co-author of "The .NET Developer's Guide to Directory Services Programming"
http://www.directoryprogramming.net
<awri...@gmail.com> wrote in message
news:060ed2df-e4c4-462c...@o36g2000yqh.googlegroups.com...

awri...@gmail.com

unread,
Mar 21, 2009, 7:54:55 AM3/21/09
to
On Mar 20, 10:41 pm, "Joe Kaplan"

<joseph.e.kap...@removethis.accenture.com> wrote:
> What you are doing is working and is fine.  You can also use the constructor
> that takes a byte() if you like.
>
> You are just being mislead by the lack of a good ToString() override on the
> X500DistinguishedName class.  If you access the Name property of the class,
> that will show you what you expect to see.
>
> --
> Joe Kaplan-MS MVP Directory Services Programming
> Co-author of "The .NET Developer's Guide to Directory Services Programming"http://www.directoryprogramming.net<awrigh...@gmail.com> wrote in message

>
> news:060ed2df-e4c4-462c...@o36g2000yqh.googlegroups.com...
>
>
>
> > Using vb.net, 3.5 framework.  I have an array, which contains a base64
> > encoded x509 certificate.  I need to convert that to a
> > x509certificate2 object for later use in my project, but I'm having
> > problems.  Here's what I have.
>
> > Dim orgCert As New X509Certificate2()
> > Dim certbytes As Byte() = Convert.FromBase64String(strOrg(2))  'this
> > value in the array contains the cert
> > orgCert.Import(certbytes)
> > Console.WriteLine(orgCert.SubjectName)
> > Console.WriteLine(strOrg(2))
>
> > The output for "Console.WriteLine(orgCert.SubjectName)" is simply
> > "System.Security.Cryptography.X509Certificates.X500DistinguishedName"
> > instead of the actual SubjectName of the certificate, giving me the
> > impression that the certificate has somehow gotten mangled.
>
> > However, if I take the output of "Console.WriteLine(strOrg(2))" and
> > copy/paste it to notepad, save as filename.cer, Windows sees it as a
> > valid certificate.  So, what's happening when I try and convert the
> > base64 encoded string item to a byte array?  Any other idea how to do
> > this?  Thanks.
>
> > Steve- Hide quoted text -
>
> - Show quoted text -

Thanks. Didn't realize I was chasing a non-problem.

Steve

0 new messages