다음 코드는 작동하지 않습니다ProtectedData.Unprotect() 이후로 가장()
IntPtr token = Win32Dll.LogonUser(“user1”, “mydomain”, “password1”);
WindowsIdentity id = new WindowsIdentity(token);
WindowsImpersonationContext ic = id.Impersonate();
byte[] unprotectedBytes = ProtectedData.Unprotect(passwordBytes, null, DataProtectionScope.CurrentUser);
password = Encoding.Unicode.GetString(unprotectedBytes);
ic.Undo();
암호가 해독되지 않습니다.
MSDN은
"If you use this method during impersonation, you may receive the following error: "Key not valid for use in specified state." This error can be prevented by loading the profile of the user you want to impersonate, before calling the method."
감사 AdjustTokenPrivileges를 사용하여 privs 및 활성화 할 수 있습니다. 하지만 "... id.Impersonate();"뒤에 LoadUserProfile()을 호출하려고했습니다. 코드는 여전히 작동하지 않았습니다. 또한 함수 LoadUserProfile() (반환 IntPtr 토큰)의 결과를 어떻게 처리해야할지 모르겠다. LoadUserProfile()을 그냥 호출합니까? 토큰으로 무엇인가해야합니까? – Andrey
LoadUserProfile의 결과를 어떻게 처리해야할지 모르겠군요. 나는 당신의 문제를 재현하려했지만 당신이 묘사 한 예외를 결코 얻지 못한다. 로컬 및 도메인 계정으로 테스트했지만 ProtectedData.Protect는 항상 성공합니다. 행운을 빌어 요, 해결책을 찾으면 관심을 가질 수 있습니다 ... –
@rwwilden : 보호 해제, 보호 해제. –