/** * @return <c>true</c> if the keyDigest is compatible with the specified saltData and saltHash */ public bool Validate(byte[] saltData, byte[] saltHash) { Check16Bytes(saltData, "saltData"); Check16Bytes(saltHash, "saltHash"); // validation uses the RC4 for block zero RC4 rc4 = CreateRC4(0); byte[] saltDataPrime = new byte[saltData.Length]; Array.Copy(saltData, saltDataPrime, saltData.Length); rc4.Encrypt(saltDataPrime); byte[] saltHashPrime = new byte[saltHash.Length]; Array.Copy(saltHash, saltHashPrime, saltHash.Length); rc4.Encrypt(saltHashPrime); using (MD5 md5 = MD5.Create()) { byte[] finalSaltResult = md5.ComputeHash(saltDataPrime); //if (false) //{ // set true to see a valid saltHash value // byte[] saltHashThatWouldWork = xor(saltHash, xor(saltHashPrime, finalSaltResult)); // Console.WriteLine(HexDump.ToHex(saltHashThatWouldWork)); //} return(Arrays.Equals(saltHashPrime, finalSaltResult)); } }
private void RekeyForNextBlock() { _currentKeyIndex = _streamPos / RC4_REKEYING_INTERVAL; _rc4 = _key.CreateRC4(_currentKeyIndex); _nextRC4BlockStart = (_currentKeyIndex + 1) * RC4_REKEYING_INTERVAL; }