SecretManagement.Chromium.Extension/Classes/ChromiumCredentialEntry.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
28
29
30
31
32
using namespace Microsoft.Powershell.SecretManagement
using namespace System.Security.Cryptography
using namespace System.Data
class ChromiumCredentialEntry {
    [uri]$Target
    [PSCredential]$Credential

    ChromiumCredentialEntry ([DataRow]$DataRow) {
        $this.Target = $DataRow.origin_url
        $password = $DataRow.password_value

        [Text.Encoding]::Default.GetString(
            [ProtectedData]::Unprotect(
                $DataRow.password_value,
                $null,
                [DataProtectionScope]::CurrentUser
            )
        ) | ConvertTo-SecureString -AsPlainText -Force
        
        $this.Credential = [PSCredential]::new(
            $DataRow.username_value, #username
            $password
        )
    }

    # [SecretInformation] ToSecretInformation() {
    # return $this.Credential.Username + "@" + $this.Target.Host
    # }
    [String] ToString() {
        return $this.Credential.Username + "@" + $this.Target.Host
    }
}