Get string representation of certificates

Posted on 1/13/2013 @ 5:20 PM in #Vanilla .NET by | Feedback | 1348 views

Frequently you need to embed certificates as a string in your .configs. This is especially helpful when you are trying to reduce the number of setup steps when writing code that involves certs and required in some circumstances like FederationMetadata.xml in STS’s.

Well here is a powershell script to get the string ..

$certPath = "enter your cert path here";
$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2($certPath)
$bytearray = $cert.Export([System.Security.Cryptography.X509Certificates.X509ContentType]::Cert)
$result = [System.Convert]::ToBase64String($bytearray)

At the end of this script, the $result variable will contain the string rep. of what you need.

Sound off but keep it civil:

Older comments..