Example #1
0
        private byte[] EncryptChunkHashed(byte[] buffer, int block, ContentHashes hashes, int contentID)
        {
            BigEndianMemoryStream ivStream = new BigEndianMemoryStream(16);

            ivStream.WriteBigEndian((short)contentID);
            aes.IV = ivStream.GetBuffer();
            byte[] decryptedHashes = hashes.GetHashForBlock(block);
            decryptedHashes[1] ^= (byte)contentID;

            byte[] encryptedhashes = Encrypt(decryptedHashes);
            decryptedHashes[1] ^= (byte)contentID;
            int iv_start = (block % 16) * 20;

            aes.IV = Utils.CopyOfRange(decryptedHashes, iv_start, iv_start + 16);

            byte[]       encryptedContent = Encrypt(buffer);
            MemoryStream outputStream     = new MemoryStream(0x10000);

            outputStream.Write(encryptedhashes);
            outputStream.Write(encryptedContent);

            return(outputStream.GetBuffer());
        }
Example #2
0
        private void EncryptFileHashed(Stream input, Stream output, long length, int contentID, ContentHashes hashes)
        {
            const int hashBlockSize = 0xFC00;

            byte[] buffer = new byte[hashBlockSize];
            int    read;
            int    block = 0;

            do
            {
                read = input.Read(buffer, 0, hashBlockSize);

                output.Write(EncryptChunkHashed(buffer, block, hashes, contentID));

                block++;
                if (block % 100 == 0)
                {
                    Console.Write($"\rEncryption: {(int)(100.0 * block * hashBlockSize / length)}%");
                }
            } while (read == hashBlockSize);
            Console.WriteLine("\rEncryption: 100%");
        }
Example #3
0
 public void EncryptFileHashed(FileStream input, int contentID, FileStream output, ContentHashes hashes)
 {
     EncryptFileHashed(input, output, input.Length, contentID, hashes);
 }