private void ApplyFilePass(XlsBiffFilePass filePass) { RC4Key key = new RC4Key("VelvetSweatshop", filePass.Salt); int blockNumber = 0; RC4 rc4 = key.Create(blockNumber); int position = 0; while (position < _bytes.Length - 4) { uint id = BitConverter.ToUInt16(_bytes, position); int length = BitConverter.ToUInt16(_bytes, position + 2) + 4; int startDecrypt = 4; switch ((BIFFRECORDTYPE)id) { case BIFFRECORDTYPE.BOF: case BIFFRECORDTYPE.FILEPASS: case BIFFRECORDTYPE.INTERFACEHDR: startDecrypt = length; break; case BIFFRECORDTYPE.BOUNDSHEET: startDecrypt += 4; // For some reason the sheet offset is not encrypted break; } for (int i = 0; i < length; i++) { int currentBlock = position / 1024; if (blockNumber != currentBlock) { blockNumber = currentBlock; rc4 = key.Create(blockNumber); } byte mask = rc4.Output(); if (i >= startDecrypt) { _bytes[position] = (byte)(_bytes[position] ^ mask); } position++; } } }