Example #1
0
        public byte[] Encrypt(byte[] plaintext)
        {
            AESBlock plainBlock   = new AESBlock(plaintext);
            AESBlock chipherBlock = Encrypt(plainBlock);

            return(chipherBlock.data);
        }
Example #2
0
        public byte[] Decrypt(byte[] chiphertext)
        {
            AESBlock chipherBlock = new AESBlock(chiphertext);
            AESBlock plainBlock   = Decrypt(chipherBlock);

            return(plainBlock.data);
        }
Example #3
0
 public void GenerateSubKeys()
 {
     roundKeys[0] = new AESBlock(key);
     for (int i = 0; i < ROUND_NO; ++i)
     {
         roundKeys[i + 1] = new AESBlock(roundKeys[i]);
         roundKeys[i + 1].KeyTransform(roundCoefficient[i]);
     }
 }
Example #4
0
    public void ReverseAesTest(int index)
    {
        var input    = new AESBlock(_cipher[index]);
        var aes      = new AES(_keys[index]);
        var expected = new AESBlock(_plain[index]);

        var actual = aes.Decrypt(input);

        CollectionAssert.AreEqual(expected.data, actual.data);
    }
Example #5
0
        public AESAlgo(byte[] key)
        {
            this.key = new AESBlock(key);

            for (int i = 0; i < ROUND_NO + 1; ++i)
            {
                roundKeys[i] = new AESBlock();
            }

            GenerateSubKeys();
        }
Example #6
0
        public AESBlock Decrypt(AESBlock chipherBlock)
        {
            AESBlock outputBlock = new AESBlock(chipherBlock);

            for (int r = 0; r < ROUND_NO; ++r)
            {
                outputBlock.AddRoundKey(roundKeys[ROUND_NO - r]);

                if (r > 0)
                {
                    outputBlock.inverseMixColumns();
                }

                outputBlock.InverseShiftRows();

                outputBlock.SubBytesInverse();
            }

            outputBlock.AddRoundKey(roundKeys[0]);

            return(outputBlock);
        }
Example #7
0
        public AESBlock Encrypt(AESBlock inputBlock)
        {
            AESBlock chipherBlock = new AESBlock(inputBlock);

            chipherBlock.AddRoundKey(roundKeys[0]);

            for (int r = 0; r < ROUND_NO; ++r)
            {
                chipherBlock.SubBytesForward();

                chipherBlock.ShiftRows();

                if (r < ROUND_NO - 1)
                {
                    chipherBlock.MixColumns();
                }

                chipherBlock.AddRoundKey(roundKeys[r + 1]);
            }

            return(chipherBlock);
        }