public static byte[] SHAHashXorSecret(HashAlgorithm hasher, DiffieHellman dh, byte[] keyEx, byte[] encMacKey) {
byte[] dhShared = dh.DecryptKeyExchange(keyEx);
byte[] shaDhShared = hasher.ComputeHash(ensurePositive(dhShared));
if (shaDhShared.Length != encMacKey.Length) {
throw new ArgumentOutOfRangeException(string.Format(CultureInfo.CurrentCulture,
"encMacKey's length ({0}) does not match the length of the hashing algorithm ({1}).",
encMacKey.Length, shaDhShared.Length));
}
byte[] secret = new byte[encMacKey.Length];
for (int i = 0; i < encMacKey.Length; i++) {
secret[i] = (byte)(encMacKey[i] ^ shaDhShared[i]);
}
return secret;
}