PowerShell - 시스템 디코딩.보안.읽을 수 있는 암호에 대한 SecureString
시스템에서 암호를 해독합니다.보안.읽을 수 있는 암호에 대한 SecureString.
$password = convertto-securestring "TestPassword" -asplaintext -force
$credentials = New-Object System.Net.NetworkCredential("TestUsername", $password, "TestDomain")
이 코드 부분은 정상적으로 작동합니다. $credentials 개체를 사용할 수 있습니다.하지만 나중에 코드에서 읽을 수 있는 형식의 암호가 필요합니다.메서드에는 읽을 수 있는 문자열의 암호가 필요하기 때문입니다.그래서 나는 비밀번호를 다시 해독해야 합니다.
$credentials 개체에서 암호를 디코딩하는 방법은 무엇입니까?
갱신하다
작동하지 않음:
$password = convertto-securestring "TestPassword" -asplaintext -force
$credentials = New-Object System.Net.NetworkCredential("TestUsername", $password, "TestDomain")
$Ptr = [System.Runtime.InteropServices.Marshal]::SecureStringToCoTaskMemUnicode($credentials.password)
$result = [System.Runtime.InteropServices.Marshal]::PtrToStringUni($Ptr)
[System.Runtime.InteropServices.Marshal]::ZeroFreeCoTaskMemUnicode($Ptr)
$result
여기 있습니다.
$password = ConvertTo-SecureString 'P@ssw0rd' -AsPlainText -Force
$Ptr = [System.Runtime.InteropServices.Marshal]::SecureStringToCoTaskMemUnicode($password)
$result = [System.Runtime.InteropServices.Marshal]::PtrToStringUni($Ptr)
[System.Runtime.InteropServices.Marshal]::ZeroFreeCoTaskMemUnicode($Ptr)
$result
P@ssw0rd
"시스템"의 경우.Net.NetworkCredential" 개체는 문자열 암호만 읽으면 됩니다.
$password = convertto-securestring "TestPassword" -asplaintext -force
$credentials = New-Object System.Net.NetworkCredential("TestUsername", $password, "TestDomain")
$credentials.Password
TestPassword
$credentials | gm
TypeName: System.Net.NetworkCredential
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetCredential Method System.Net.NetworkCredential GetCredential(uri uri, str
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
Domain Property string Domain {get;set;}
Password Property string Password {get;set;}
SecurePassword Property securestring SecurePassword {get;set;}
UserName Property string UserName {get;set;}
PSCredential 개체가 표시되는 경우 Get-Credential 사용과 같은 대화형 명령에서
$credentials=Get-Credential
$credentials.GetNetworkCredential().UserName
TestUsername
$credentials.GetNetworkCredential().Domain
TestDomain
$credentials.GetNetworkCredential().Password
TestPassword
자세한 내용은 http://blogs.technet.com/b/heyscriptingguy/archive/2013/03/26/decrypt-powershell-secure-string-password.aspx 을 참조하십시오.
참고: 이 예에서는 PS 4를 사용했습니다.
($credentials.GetNetworkCredential()).Password
자세한 내용은 http://blogs.msdn.com/b/besidethepoint/archive/2010/09/21/decrypt-secure-strings-in-powershell.aspx 에서 설명합니다.
그리고 저는 그것을 하는 다른 약간 다른 약간 다른 방법을 가지고 있습니다.
$pass=convertto-securestring "P@ssw0rd" -asplaintext -force | ConvertFrom-SecureString
[Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR( (ConvertTo-SecureString $pass) ))
P@ssw0rd
위에 롭이 올린 글은 어떤 이유에서인지 제게 통하지 않았습니다.저는 다른 사이트에서 답을 찾았습니다.
코드 버전의 여러 줄:
$password = ConvertTo-SecureString "P@ssw0rd" -AsPlainText -Force
$decrypted = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($password)
$decryptedPassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($decrypted)
$decryptedPassword # Outputs: P@ssw0rd
단일 라이너 버전(변수에 저장할 수 있음):
# Outputs: P@ssw0rd
[System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($password))
언급URL : https://stackoverflow.com/questions/7468389/powershell-decode-system-security-securestring-to-readable-password
'programing' 카테고리의 다른 글
| 데이터 테이블 페이지를 사용하려면 어떻게 해야 합니까? (0) | 2023.08.02 |
|---|---|
| 간단한 php 함수에서 "의존성 주입"을 어떻게 사용할 수 있으며, 번거롭게 해야 합니까? (0) | 2023.08.02 |
| 리소스에서 비트맵을 설정하는 방법 (0) | 2023.08.02 |
| Android Studio는 ProGuard 매핑 파일을 어디에 저장합니까? (0) | 2023.08.02 |
| Oracle에서 패키지에 상태가 있는지 확인할 수 있는 방법이 있습니까? (0) | 2023.08.02 |