Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##$thumb=""
- $thumb = (Get-ChildItem Cert:\LocalMachine\My\|select subject,notafter,thumbprint | ogv -PassThru ).thumbprint
- $cert=Get-ChildItem Cert:\LocalMachine\My\$thumb
- ##Public key
- $CertBase64 = [System.Convert]::ToBase64String($cert.RawData, [System.Base64FormattingOptions]::InsertLineBreaks)
- ## Private key
- $RSACng = [System.Security.Cryptography.X509Certificates.RSACertificateExtensions]::GetRSAPrivateKey($cert)
- $KeyBytes = $RSACng.Key.Export([System.Security.Cryptography.CngKeyBlobFormat]::Pkcs8PrivateBlob)
- $KeyBase64 = [System.Convert]::ToBase64String($KeyBytes, [System.Base64FormattingOptions]::InsertLineBreaks)
- ## Build pem files
- $Pemkey = @"
- -----BEGIN PRIVATE KEY-----
- $KeyBase64
- -----END PRIVATE KEY-----
- "@
- $Pemcert = @"
- -----BEGIN CERTIFICATE-----
- $CertBase64
- -----END CERTIFICATE-----
- "@
- ## Export
- $pemkey | out-file -filepath .\PEMkey.key
- $pemcert | out-file -filepath .\PEMcert.crt
Add Comment
Please, Sign In to add comment