private static KeyData GenerateKeyIV128(byte[] Key)
{
// Generate the Initialization Vector.
byte[] IVH = Hash.Compute512Byte(Key);
var IV = new byte[Bits128];
for (int i = 0; i < Bits128; i++)
IV[i] = IVH[i];
//Make sure the key is the proper length and fix it if needed.
if (Key.Length != Bits128)
{
var TempKey = new List<byte>(Key);
int c = Bits128;
while (TempKey.Count != Bits128)
{
if (TempKey.Count < Bits128)
TempKey.Add(IVH[c++]);
else if (TempKey.Count > Bits128)
TempKey.RemoveAt(0);
else
break;
if (c > IVH.Length - 1) c = Bits128;
}
Key = TempKey.ToArray();
}
var NK = new KeyData { Key = Key, IV = IV };
return NK;
}