simplify the ECB and CBC

This commit is contained in:
jonnysp 2018-09-22 07:44:52 +02:00
parent 235ace8b1b
commit ab8dda98b4

View file

@ -30,13 +30,7 @@ namespace LibHac
aes.Key = key; aes.Key = key;
aes.Mode = CipherMode.ECB; aes.Mode = CipherMode.ECB;
aes.Padding = PaddingMode.None; aes.Padding = PaddingMode.None;
var dec = aes.CreateDecryptor(); Array.Copy(aes.CreateDecryptor().TransformFinalBlock(src, srcIndex, src.Length), srcIndex, dest, destIndex, length);
using (var ms = new MemoryStream(dest, destIndex, length))
using (var cs = new CryptoStream(ms, dec, CryptoStreamMode.Write))
{
cs.Write(src, srcIndex, length);
cs.FlushFinalBlock();
}
} }
} }
@ -52,13 +46,7 @@ namespace LibHac
aes.IV = iv; aes.IV = iv;
aes.Mode = CipherMode.CBC; aes.Mode = CipherMode.CBC;
aes.Padding = PaddingMode.None; aes.Padding = PaddingMode.None;
var dec = aes.CreateDecryptor(); Array.Copy(aes.CreateDecryptor().TransformFinalBlock(src, srcIndex, src.Length), srcIndex, dest, destIndex, length);
using (var ms = new MemoryStream(dest, destIndex, length))
using (var cs = new CryptoStream(ms, dec, CryptoStreamMode.Write))
{
cs.Write(src, srcIndex, length);
cs.FlushFinalBlock();
}
} }
} }
@ -74,13 +62,7 @@ namespace LibHac
aes.IV = iv; aes.IV = iv;
aes.Mode = CipherMode.CBC; aes.Mode = CipherMode.CBC;
aes.Padding = PaddingMode.None; aes.Padding = PaddingMode.None;
var dec = aes.CreateEncryptor(); Array.Copy(aes.CreateEncryptor().TransformFinalBlock(src, srcIndex, src.Length), srcIndex, dest, destIndex, length);
using (var ms = new MemoryStream(dest, destIndex, length))
using (var cs = new CryptoStream(ms, dec, CryptoStreamMode.Write))
{
cs.Write(src, srcIndex, length);
cs.FlushFinalBlock();
}
} }
} }