コード例 #1
0
        public void GenerateKeyWithCorrectLength()
        {
            AESCipherHelper helper = new AESCipherHelper(blockSize);
            Bytes           key    = helper.GenerateKey();

            Assert.IsTrue(((Hex)key).Length == blockSize);
        }
コード例 #2
0
        public void UnPadKey()
        {
            AESCipherHelper helper   = new AESCipherHelper(20);
            string          key      = "YELLOW SUBMARINE\x04\x04\x04\x04";
            string          expected = "YELLOW SUBMARINE";
            string          actual   = helper.RemovePadding(key);

            Assert.AreEqual(expected, actual);
        }
コード例 #3
0
        public void Oracle()
        {
            EncryptionOracle eo     = new EncryptionOracle();
            AESCipherHelper  helper = new AESCipherHelper();

            for (int i = 0; i < 100; i++)
            {
                Random r = new Random();
                Tuple <Base64, string> encrypted = eo.EncryptWithRandomPadding(new String((char)r.Next(255), 100));
                Assert.IsTrue((helper.IsECB(encrypted.Item1.Decode()) && encrypted.Item2 == "EBC") || (encrypted.Item2 == "CBC"));
            }
        }
コード例 #4
0
        public void UnPadInvalidKeys2()
        {
            AESCipherHelper helper   = new AESCipherHelper(20);
            string          key      = "YELLOW SUBMARINE\x01\x02\x03\x04";
            string          expected = "Invalid Padding";

            try
            {
                string actual = helper.RemovePadding(key);
                Assert.Fail("Exception not thrown");
            }
            catch (Exception ex)
            {
                Assert.AreEqual(expected, ex.Message);
            }
        }
コード例 #5
0
        public void DetectECB()
        {
            AESCipherHelper helper   = new AESCipherHelper(blockSize);
            string          expected = "d880619740a8a19b7840a8a31c810a3d08649af70dc06f4fd5d2d69c744cd283e2dd052f6b641dbf9d11b0348542bb5708649af70dc06f4fd5d2d69c744cd2839475c9dfdbc1d46597949d9c7e82bf5a08649af70dc06f4fd5d2d69c744cd28397a93eab8d6aecd566489154789a6b0308649af70dc06f4fd5d2d69c744cd283d403180c98c8f6db1f2a3f9c4040deb0ab51b29933f2c123c58386b06fba186a";
            string          actual   = "";

            foreach (string line in File.ReadAllLines(@"TestFiles\AESinECBdetection.txt"))
            {
                if (helper.IsECB(line))
                {
                    actual = line;
                    break;
                }
            }

            Assert.AreEqual(expected, actual);
        }
コード例 #6
0
        public void GenerateUniqueKeys()
        {
            AESCipherHelper helper = new AESCipherHelper(16);
            List <Bytes>    keys   = new List <Bytes>();

            while (keys.Count < 100)
            {
                Bytes key = helper.GenerateKey();
                if (!keys.Contains(key))
                {
                    keys.Add(key);
                }
                else
                {
                    throw new Exception("Duplicate key");
                }
            }

            Assert.IsTrue(keys.Count == 100);
        }
コード例 #7
0
 public AESCracker(Base64 unknownString)
 {
     this.eo            = new EncryptionOracle();
     this.helper        = new AESCipherHelper();
     this.unknownString = unknownString;
 }