Showing posts with label Java equivalent of C# AES Decryption. Show all posts
Showing posts with label Java equivalent of C# AES Decryption. Show all posts

Thursday 17 December 2015

Java equivalent of C# AES Decryption

 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, 8, encryptedData.Length - 8, output, 0);
            cipher.DoFinal(output, len);
            // byte[] output = cipher.DoFinal(encryptedData);
            return output;
        }