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.