我们创建的一个实用程序在C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys.中生成了太多的文件为了安全地删除这些文件,我想打开每个文件并检查密钥。如何在C#中打开这些密钥文件?我查看了here的代码。代码只返回公钥。我可以从这些密钥文件中获得更多信息吗?
发布于 2019-11-27 05:08:48
我最终使用下面的powershell从证书存储中获取有效密钥的列表。我还将c2319c42033a5ca7f44e731bfd3fa2b5添加到列表中,因为我正在使用IIS服务。我删除任何不在此列表中的密钥文件。
$MachineCertStores = Get-ChildItem Cert:\LocalMachine
$UserCertStores = Get-ChildItem Cert:\CurrentUser
Foreach ($Store in $MachineCertStores)
{
$path = "Cert:\LocalMachine\" + $($store.Name)
$keys = Get-ChildItem $path
Foreach ($Key in $Keys)
{
$UniqueKeyName = $key.PrivateKey.CspKeyContainerInfo.UniqueKeyContainerName
if ([string]::IsNullOrWhitespace($UniqueKeyName)){
}else{
write-host $UniqueKeyName
$file = Get-Content "validkey.txt"
$containsWord = $file | %{$_ -match $UniqueKeyName.substring(0,32)}
If($containsWord -contains $true)
{
}else{
$UniqueKeyName.substring(0,32) | Out-File 'validkey.txt' -Append
}
}
}
}
Foreach ($Store in $UserCertStores)
{
$path = "Cert:\CurrentUser\" + $($store.Name)
$keys = Get-ChildItem $path
Foreach ($Key in $Keys)
{
$UniqueKeyName = $key.PrivateKey.CspKeyContainerInfo.UniqueKeyContainerName
if ([string]::IsNullOrWhitespace($UniqueKeyName)){
}else{
write-host $UniqueKeyName
$file = Get-Content "validkey.txt"
$containsWord = $file | %{$_ -match $UniqueKeyName.substring(0,32)}
If($containsWord -contains $true)
{
}else{
$UniqueKeyName.substring(0,32) | Out-File 'validkey.txt' -Append
}
}
}
}https://stackoverflow.com/questions/59035998
复制相似问题