Azure Cloud Service解码RDP用户的密码

时间:2013-10-30 14:13:14

标签: azure credentials rdp

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

2 个答案:

答案 0 :(得分: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);
}

答案 1 :(得分: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的优秀答案的调整)