Guest User

Untitled

a guest
Jun 19th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. # setup certificate properties including the commonName (DNSName) property for Chrome 58+
  2. $certificate = New-SelfSignedCertificate `
  3. -Subject localhost `
  4. -DnsName localhost `
  5. -KeyAlgorithm RSA `
  6. -KeyLength 2048 `
  7. -NotBefore (Get-Date) `
  8. -NotAfter (Get-Date).AddYears(2) `
  9. -CertStoreLocation "cert:CurrentUser\My" `
  10. -FriendlyName "Localhost Certificate for .NET Core" `
  11. -HashAlgorithm SHA256 `
  12. -KeyUsage DigitalSignature, KeyEncipherment, DataEncipherment `
  13. -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.1")
  14. $certificatePath = 'Cert:\CurrentUser\My\' + ($certificate.ThumbPrint)
  15.  
  16. # create temporary certificate path
  17. $tmpPath = "C:\tmp"
  18. If(!(test-path $tmpPath))
  19. {
  20. New-Item -ItemType Directory -Force -Path $tmpPath
  21. }
  22.  
  23. # set certificate password here
  24. $pfxPassword = ConvertTo-SecureString -String "YourSecurePassword" -Force -AsPlainText
  25. $pfxFilePath = "c:\tmp\localhost.pfx"
  26. $cerFilePath = "c:\tmp\localhost.cer"
  27.  
  28. # create pfx certificate
  29. Export-PfxCertificate -Cert $certificatePath -FilePath $pfxFilePath -Password $pfxPassword
  30. Export-Certificate -Cert $certificatePath -FilePath $cerFilePath
  31.  
  32. # import the pfx certificate
  33. Import-PfxCertificate -FilePath $pfxFilePath Cert:\LocalMachine\My -Password $pfxPassword -Exportable
  34.  
  35. # trust the certificate by importing the pfx certificate into your trusted root
  36. Import-Certificate -FilePath $cerFilePath -CertStoreLocation Cert:\CurrentUser\Root
  37.  
  38. # optionally delete the physical certificates (don't delete the pfx file as you need to copy this to your app directory)
  39. # Remove-Item $pfxFilePath
  40. Remove-Item $cerFilePath
Add Comment
Please, Sign In to add comment