Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
Java of AES Encryption======================= Cipher encrypt = Cipher.getInstance("AES"); encrypt.init(Cipher.ENCRYPT_MODE, key); byte[] encryptedData = encrypt.doFinal(data);
C# code using Rijndael(AES) 128 Bit encryption==============================================
ICryptoTransform transform = GetCryptoServiceProvider(SecretKey); //Set up the stream that will hold the encrypted data. MemoryStream memStreamEncryptedData = GetMemoryStream(transform, bytesData);
/// <summary> /// Create ICryptoTransform object from Rijndael(AES) ECB/PKCS7 /// </summary> /// <param name="bytesKey">Byte Array key</param> /// <returns>ICryptoTransform Object</returns> private ICryptoTransform GetCryptoServiceProvider(byte[] bytesKey) { Rijndael rijndael = new RijndaelManaged(); try { rijndael.KeySize = 128; rijndael.BlockSize = 128; rijndael.Mode = CipherMode.ECB; rijndael.Padding = PaddingMode.PKCS7; // Test to see if a key was provided rijndael.GenerateIV(); if (null != bytesKey) { rijndael.Key = bytesKey; } else { rijndael.GenerateKey(); SecretKey = rijndael.Key; } } catch (Exception Ex) { throw new Exception("Error while creating Rijndael(AEs) Object: \n" + Ex.Message); } return rijndael.CreateEncryptor(); }