0

我在 Azure 中丢失了 RDP 的密码。但我有加密密码的 cscfg 文件和证书。如何从 cscfg 文件中获取密码?

4

2 回答 2

6
function DecodePassword([string] $encodedPassword)
{
    $encodedMessage = [Convert]::FromBase64String($encodedPassword);
    $cms = New-Object System.Security.Cryptography.Pkcs.EnvelopedCms;
    $cms.Decode($encodedMessage);

    $store = $null;
    try
    {
        $store = New-Object System.Security.Cryptography.X509Certificates.X509Store('My', 'CurrentUser');
        $cms.Decrypt($store.Certificates);
    }
    finally
    {
        $store.Close();
    }

    return [Text.Encoding]::UTF8.GetString($cms.ContentInfo.Content);
}
于 2013-10-30T14:13:14.487 回答
0

谢谢!这对我来说是一个严重的救生员!这是我为方便命令行调用而调整的版本(并添加了 System.Security 的加载):

$error.clear()
function DecodePassword([string] $encodedPassword)
{
    [System.Reflection.Assembly]::LoadWithPartialName("System.Security") | out-null;
    $encodedMessage = [Convert]::FromBase64String($encodedPassword);
    $cms = New-Object System.Security.Cryptography.Pkcs.EnvelopedCms;
    $cms.Decode($encodedMessage);

    $store = $null;
    try
    {
        $store = New-Object System.Security.Cryptography.X509Certificates.X509Store('My', 'CurrentUser');
        $cms.Decrypt($store.Certificates);
    }

    finally
    {
        $store.Close();
    }

    return [Text.Encoding]::UTF8.GetString($cms.ContentInfo.Content);
}

$password = DecodePassword($args[0]);
Write-Host Decoded password: """$password""";

可以简单地调用为:

>powershell -f DecodeRemotePassword.ps1 "PASTE_ENCODED_PASSWORD_HERE"

(请不要投票,因为这只是 Alexey 出色答案的一个调整)

于 2014-03-28T19:25:07.220 回答