Showing posts with label SSL. Show all posts
Showing posts with label SSL. Show all posts

Tuesday, 25 October 2011

Convert SSL Certificate .cer to .pfx

If you were like me working on Azure projects and suddenly was required to upload your SSL certificate and hit the dead end trying to figure out how to convert the file to .pfx, you have come to the right place, follow these simple steps and you'll be good to go.

PowerShell Script
$c = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2("c:\mycert.cer")
$bytes = $c.Export("Pfx","password")
[System.IO.File]::WriteAllBytes("c:\mycert.pfx", $bytes)

and just incase if you got the error cannot find type [System.Security.Cryptography.X509.....

Try running this to see if you have the System.dll loaded (should be by default):
[AppDomain]::CurrentDomain.GetAssemblies() |
    Where {$_.Location -match '\\System\\'}

If it is loaded then this command should show the X509Certificate2 type:
[AppDomain]::CurrentDomain.GetAssemblies() |
Where {$_.Location -match '\\System\\'} |
%{$_.GetExportedTypes()} | Where {$_.Name -match 'X509Cert'}
If the System.dll isn't loaded (which would be odd) try loading it:
Add-Type -AssembyName System

Wednesday, 1 June 2011

Create SSL test Certificate

Open a Visual Studio Command Prompt


Change your active directory to the location where you wish to place your certificate


Enter the following command

makecert -r -pe -n "CN=AzureSSL" -sky 1 "azuressl.cer" -sv "azuressl.pvk" -ss My




after the process has succeeded


Now enter the following command

pvk2pfx -pvk "azuressl.pvk" -spc "azuressl.cer" -pfx "azuressl.pfx" -pi password1


and you are good to go, you have your test certificate