Showing posts with label Decryption in AES c#. Show all posts
Showing posts with label Decryption in AES c#. Show all posts

Thursday 17 December 2015

Decryption in AES c#

 public byte[] Decrypt(byte[] encryptedData, RijndaelManaged rijndaelManaged)
        {
            byte[] AESKey = new byte[] { };
            KeyParameter par = new KeyParameter(AESKey);
            // SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
            IBufferedCipher cipher = CipherUtilities.GetCipher("AES/ECB/NoPadding");
            cipher.Init(false, par);
            // Gives me "pad block corrupted" error
            byte[] output = new byte[cipher.GetOutputSize(encryptedData.Length)];
            int len = cipher.ProcessBytes(encryptedData, 0, encryptedData.Length , output, 0);
            cipher.DoFinal(output, len);
            // byte[] output = cipher.DoFinal(encryptedData);
            return output;
        }