Skip to content

Instantly share code, notes, and snippets.

@plambrechtsen
Created November 28, 2023 02:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plambrechtsen/e622ec6805e92000695e925d2e31ee02 to your computer and use it in GitHub Desktop.
Save plambrechtsen/e622ec6805e92000695e925d2e31ee02 to your computer and use it in GitHub Desktop.
Generate Azure Self Signed Certificate for SAML
# Generate a 5 year self signed cert without KeyUsage, Subject Key Identifier and Enhanced Key Usage
# As per: https://learn.microsoft.com/en-us/powershell/module/pki/new-selfsignedcertificate
$Certificate=New-SelfSignedCertificate –Subject "SAML SSO Certificate" -CertStoreLocation Cert:\CurrentUser\My -KeyUsage None -KeyAlgorithm RSA -KeyLength 2048 -KeyExportPolicy Exportable -NotAfter (Get-Date).AddYears(5) -SuppressOid "2.5.29.14","2.5.29.37"
# Exported DER binary public key file
Export-Certificate -Cert $Certificate -FilePath ".\SSO.cer"
# Exported PEM text format public key file
$pemFileContent = @(
'-----BEGIN CERTIFICATE-----'
[System.Convert]::ToBase64String($Certificate.RawData, 'InsertLineBreaks')
'-----END CERTIFICATE-----'
)
$pemFileContent | Out-File -FilePath '.\SSO.pem' -Encoding ascii
# Exported PKCS12/PFX private key with a password of "password"
$Pwd = ConvertTo-SecureString -String "password" -Force -AsPlainText
Export-PfxCertificate -Cert $Certificate -FilePath ".\SSO.pfx" -Password $Pwd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment