proxy.exeでは、次の方法で安全な文字列を作成しています。
public SecureString GetSecureEncryptionKey()
{
string strPassword = "8charPwd";
SecureString secureStr = new SecureString();
if (strPassword.Length > 0)
{
foreach (var c in strPassword.ToCharArray()) secureStr.AppendChar(c);
}
return secureStr;
}
次に、main.exeで、次の関数を使用して復号化しています。
public string convertToUNSecureString(SecureString secstrPassword)
{
IntPtr unmanagedString = IntPtr.Zero;
try
{
unmanagedString = Marshal.SecureStringToGlobalAllocUnicode(secstrPassword);
return Marshal.PtrToStringUni(unmanagedString);
}
finally
{
Marshal.ZeroFreeGlobalAllocUnicode(unmanagedString);
}
}
問題は、返された文字列が空であることです。 main.exe内の最初の文字列を暗号化しない限り、返された復号化された文字列は実際には "8charPwd" です。なぜこうなった?SecureString 暗号化は実行可能ファイルにバインドされていますか?