Esempio n. 1
0
        public static byte[] ElectronicCodebookModeDecrypt(byte[] ciphertext, byte[] key)
        {
            List <byte> listBytePlaintext = new List <byte>();

            for (int i = 0; i < ciphertext.Length / 16; i++)
            {
                byte[] bytesBlock = HelpfulFunctions.SubArrayDeepClone(ciphertext, i * 16, 16);
                listBytePlaintext.AddRange(AESFunctions.AES_Decrypt_block(bytesBlock, key));
            }

            return(listBytePlaintext.ToArray());
        }
Esempio n. 2
0
        public static byte[] PropagatingCipherBlockChainingModeDecrypt(byte[] ciphertext, byte[] key, byte[] IV)
        {
            List <byte> listBytePlaintext = new List <byte>();

            byte[] tmp = IV;
            for (int i = 0; i < ciphertext.Length / 16; i++)
            {
                byte[] bytesBlock         = HelpfulFunctions.SubArrayDeepClone(ciphertext, i * 16, 16);
                byte[] bytesFromDecryptor = AESFunctions.AES_Decrypt_block(bytesBlock, key);
                byte[] plaintextBlock     = HelpfulFunctions.ExclusiveOR(bytesFromDecryptor, tmp);
                listBytePlaintext.AddRange(plaintextBlock);
                tmp = HelpfulFunctions.ExclusiveOR(bytesBlock, plaintextBlock);
            }

            return(listBytePlaintext.ToArray());
        }
Esempio n. 3
0
        public static byte[] PropagatingCipherBlockChainingMode2Decrypt(byte[] ciphertext, byte[] key, byte[] IV)
        {
            List <byte> listBytePlaintext = new List <byte>();

            byte[] tmp  = IV;
            byte[] tmp2 = { 1 };
            for (int i = 0; i < ciphertext.Length / 16; i++)
            {
                byte[] bytesBlock = HelpfulFunctions.SubArrayDeepClone(ciphertext, i * 16, 16);
                byte[] tmp2Copy   = tmp2;
                tmp2       = bytesBlock;
                bytesBlock = AESFunctions.AES_Decrypt_block(bytesBlock, key);
                if (i != 0)
                {
                    bytesBlock = HelpfulFunctions.ExclusiveOR(bytesBlock, tmp2Copy);
                }
                tmp = HelpfulFunctions.ExclusiveOR(bytesBlock, tmp);
                listBytePlaintext.AddRange(tmp);
            }

            return(listBytePlaintext.ToArray());
        }