-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhsm.ps1
27 lines (22 loc) · 1009 Bytes
/
hsm.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
$store = New-Object System.Security.Cryptography.X509Certificates.X509Store("MY", "LocalMachine")
$store.Open("ReadOnly")
$certificates = $store.Certificates
foreach ($certificate in $certificates) {
Write-Host "Subject: $($certificate.Subject)"
Write-Host "Issuer: $($certificate.Issuer)"
$privateKey = $certificate.PrivateKey
if ($privateKey) {
Write-Host "Key Algorithm: $($privateKey.KeyAlgorithm)"
Write-Host "Key Size (bits): $($privateKey.KeySize)"
Write-Host "Key Exportable: $($privateKey.Exportable)"
if ($privateKey.Exportable) {
$keyPath = "C:\Path\To\Save\Keys\$($certificate.Thumbprint).pfx"
$privateKey | Export-Certificate -FilePath $keyPath -Password (Read-Host "Enter password for the exported key") -Exportable
Write-Host "Exported key for $($certificate.Subject) to $keyPath"
}
} else {
Write-Host "No private key found for the certificate."
}
Write-Host
}
$store.Close()