7
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Windows 10 Pro の PowerShell で自己署名証明書(SHA-2)を作成する

Posted at

Windows 10 Pro 以外で動くかどうかは知らない備忘録

New-SelfCert.ps1
# localhost 向け
$dns = "localhost"
# なんとなく有効期間100年
$after = (Get-Date).AddYears(100)

# 「個人」に証明書を作成
$my = "cert:\CurrentUser\My"
$cert = New-SelfSignedCertificate -DnsName $dns -CertStoreLocation $my -NotAfter $after

# cer を確保
$root = "cert:\CurrentUser\Root"
$cerfile  = "localhost.cer"
Export-Certificate -Cert $cert -FilePath $cerfile

# [信頼されたルート証明機関]に cer を登録 (直接は作れなかった)
Import-Certificate -FilePath $cerfile -CertStoreLocation $root

# pfx を確保
$pfxfile  = "localhost.pfx"
$password = "password"
$sspwd = ConvertTo-SecureString -String $password -Force -AsPlainText 
Export-PfxCertificate -Cert $cert -FilePath $pfxfile -Password $sspwd

# 最初に作成した 「個人」の証明書を削除
Remove-Item -Path ($cert.PSPath)
7
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?