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
| unsafe static bool Match(SecureString s1, SecureString s2)
{
if (s1.Length != s2.Length)
return false;
IntPtr bs1 = Marshal.SecureStringToBSTR(s1);
IntPtr bs2 = Marshal.SecureStringToBSTR(s2);
char* ps1 = (char*) bs1.ToPointer();
char* ps2 = (char*) bs2.ToPointer();
try
{
for (int i = 0; i < s1.Length; i++)
if (ps1[i] != ps2[i])
return false;
return true;
}
finally
{
if (IntPtr.Zero != bs1)
Marshal.ZeroFreeBSTR(bs1);
if (IntPtr.Zero != bs2)
Marshal.ZeroFreeBSTR(bs2);
}
} |
Partager