private static void processData(FileStream inStream, long inDataLen, FileStream outStream, long outDataLen, BlockStreamCrypter bsc) { int bufSize = 0x200000; byte[] buf = new byte[bufSize]; long filePos = 0; while (filePos < inDataLen) { int reqLen = (int)Math.Min(inDataLen - filePos, bufSize); int trLen = inStream.Read(buf, 0, reqLen); if (trLen != reqLen) { throw new Exception("Incomplete data chunk read from file."); } int chunkLen = (trLen + blockSize - 1) / blockSize * blockSize; for (int i = trLen; i <= chunkLen; i++) { buf[i] = 0; } for (int pos = 0; pos < chunkLen; pos += blockSize) { bsc.crypt(buf, pos); } reqLen = (int)Math.Min(outDataLen - filePos, chunkLen); outStream.Write(buf, 0, reqLen); filePos += chunkLen; } }
private static long readDataLength(FileStream stream, BlockStreamCrypter bsc) { byte[] buf = new byte[blockSize]; int trLen = stream.Read(buf, 0, blockSize); if (trLen != blockSize) { throw new Exception("Unable to read data length suffix."); } bsc.crypt(buf, 0); return(unpackDataLength(buf)); }
private static void writeDataLength(FileStream stream, long dataLength, BlockStreamCrypter bsc) { byte[] a = packDataLength(dataLength); bsc.crypt(a, 0); stream.Write(a, 0, blockSize); }
private static long readDataLength(FileStream stream, BlockStreamCrypter bsc) { byte[] buf = new byte[blockSize]; int trLen = stream.Read(buf, 0, blockSize); if (trLen != blockSize) { throw new Exception("Unable to read data length suffix."); } bsc.crypt(buf, 0); return unpackDataLength(buf); }