private void GenerateKeyIV(string strKey, byte[] bSalt, out byte[] bEncKey, out byte[] bEncIV) { // Extracted from http://www.jensign.com/JavaScience/dotnet/DeriveKeyM/ // by Michel Gallant int HASHLENGTH = 16; byte[] bKey = Encoding.UTF8.GetBytes(strKey); int count = 1; int miter = 3; byte[] keymaterial = new byte[HASHLENGTH * miter]; byte[] data00 = new byte[bKey.Length + bSalt.Length]; Array.Copy(bKey, data00, bKey.Length); Array.Copy(bSalt, 0, data00, bKey.Length, bSalt.Length); MD5 md5 = new MD5CryptoServiceProvider(); byte[] result = null; byte[] hashtarget = new byte[HASHLENGTH + data00.Length]; for (int j = 0; j < miter; j++) { if (j == 0) result = data00; else { Array.Copy(result, hashtarget, result.Length); Array.Copy(data00, 0, hashtarget, result.Length, data00.Length); result = hashtarget; } for (int i = 0; i < count; i++) result = md5.ComputeHash(result); Array.Copy(result, 0, keymaterial, j * HASHLENGTH, result.Length); } bEncKey = new byte[32]; bEncIV = new byte[16]; Array.Copy(keymaterial, 0, bEncKey, 0, 32); Array.Copy(keymaterial, 32, bEncIV, 0, 16); }