-
Notifications
You must be signed in to change notification settings - Fork 94
/
Copy pathDecode-Text.ps1
38 lines (32 loc) · 1.2 KB
/
Decode-Text.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
33
34
35
36
37
38
# http://www.powershelladmin.com/wiki/Powershell_prompt_for_password_convert_securestring_to_plain_text
function Decode-Text {
param (
[string]$Text,
[validateset('SecureString', 'SecureStringWithKey', 'Base64', 'ASCII')]
[string]$Method = 'Base64'
)
process {
if (!$Text) {
$Text = $input
}
}
end {
switch ($method) {
'SecureString' {
(New-Object pscredential ' ', (ConvertTo-SecureString $text)).GetNetworkCredential().Password
#$marshal = [Runtime.InteropServices.Marshal]
#$marshal::PtrToStringAuto( $marshal::SecureStringToBSTR(($text | convertto-securestring)) )
}
'SecureStringWithKey' {
(New-Object pscredential ' ', (ConvertTo-SecureString $text -Key (1..16))).GetNetworkCredential().Password
}
'Base64' {
[System.Text.Encoding]::Unicode.GetString([System.Convert]::FromBase64String($text))
}
'ASCII' {
$pwlength = $text.Length / 3 - 1
-join(0..$pwlength | % {[char](32 + $text.Substring(($_*3), 3))})
}
}
}
}