首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >读取位于C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys中的密钥文件

读取位于C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys中的密钥文件
EN

Stack Overflow用户
提问于 2019-11-26 00:17:29
回答 1查看 2K关注 0票数 1

我们创建的一个实用程序在C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys.中生成了太多的文件为了安全地删除这些文件,我想打开每个文件并检查密钥。如何在C#中打开这些密钥文件?我查看了here的代码。代码只返回公钥。我可以从这些密钥文件中获得更多信息吗?

EN

回答 1

Stack Overflow用户

发布于 2019-11-27 05:08:48

我最终使用下面的powershell从证书存储中获取有效密钥的列表。我还将c2319c42033a5ca7f44e731bfd3fa2b5添加到列表中,因为我正在使用IIS服务。我删除任何不在此列表中的密钥文件。

代码语言:javascript
复制
 $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
            }
        }
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59035998

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档