Ejemplo n.º 1
0
        public static byte[] AESEncryptionOracle(byte[] input, out bool isECB)
        {
            var randomPrefixLength = random.Next(5, 11);
            var randomPrefixBuffer = new byte[randomPrefixLength];

            random.NextBytes(randomPrefixBuffer);

            var randomSuffixLength = random.Next(5, 11);
            var randomSuffixBuffer = new byte[randomSuffixLength];

            random.NextBytes(randomSuffixBuffer);

            var paddedInput = new byte[randomPrefixLength + input.Length + randomSuffixLength];

            Array.Copy(randomPrefixBuffer, 0, paddedInput, 0, randomPrefixLength);
            Array.Copy(input, 0, paddedInput, randomPrefixLength, input.Length);
            Array.Copy(randomSuffixBuffer, 0, paddedInput, randomPrefixLength + input.Length, randomSuffixLength);

            if (paddedInput.Length % 16 != 0)
            {
                paddedInput = BlockPad(paddedInput, paddedInput.Length + (16 - paddedInput.Length % 16));
            }

            isECB = random.Next(0, 2) == 1;

            if (isECB)
            {
                return(AES128.EncryptECB(paddedInput, randomKey));
            }
            else
            {
                var iv = RandomAES128Key();
                return(AES128.EncryptCBC(paddedInput, randomKey, iv));
            }
        }
Ejemplo n.º 2
0
        public static byte[] ECBOracle(byte[] randomPrefix, byte[] input)
        {
            var prefixLength = randomPrefix == null ? 0 : randomPrefix.Length;

            var unknown = Convert.FromBase64String("Um9sbGluJyBpbiBteSA1LjAKV2l0aCBteSByYWctdG9wIGRvd24gc28gbXkgaGFpciBjYW4gYmxvdwpUaGUgZ2lybGllcyBvbiBzdGFuZGJ5IHdhdmluZyBqdXN0IHRvIHNheSBoaQpEaWQgeW91IHN0b3A/IE5vLCBJIGp1c3QgZHJvdmUgYnkK");
            var payload = new byte[prefixLength + input.Length + unknown.Length];

            if (prefixLength > 0)
            {
                randomPrefix.CopyTo(payload, 0);
            }
            input.CopyTo(payload, prefixLength);
            unknown.CopyTo(payload, prefixLength + input.Length);
            return(AES128.EncryptECB(payload, randomKey));
        }