From ab8dda98b4db53161777d47df7f2c81667924eea Mon Sep 17 00:00:00 2001 From: jonnysp Date: Sat, 22 Sep 2018 07:44:52 +0200 Subject: [PATCH] simplify the ECB and CBC --- LibHac/Crypto.cs | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/LibHac/Crypto.cs b/LibHac/Crypto.cs index 8cdb178a..3fc623c7 100644 --- a/LibHac/Crypto.cs +++ b/LibHac/Crypto.cs @@ -30,13 +30,7 @@ namespace LibHac aes.Key = key; aes.Mode = CipherMode.ECB; aes.Padding = PaddingMode.None; - var dec = aes.CreateDecryptor(); - using (var ms = new MemoryStream(dest, destIndex, length)) - using (var cs = new CryptoStream(ms, dec, CryptoStreamMode.Write)) - { - cs.Write(src, srcIndex, length); - cs.FlushFinalBlock(); - } + Array.Copy(aes.CreateDecryptor().TransformFinalBlock(src, srcIndex, src.Length), srcIndex, dest, destIndex, length); } } @@ -52,13 +46,7 @@ namespace LibHac aes.IV = iv; aes.Mode = CipherMode.CBC; aes.Padding = PaddingMode.None; - var dec = aes.CreateDecryptor(); - using (var ms = new MemoryStream(dest, destIndex, length)) - using (var cs = new CryptoStream(ms, dec, CryptoStreamMode.Write)) - { - cs.Write(src, srcIndex, length); - cs.FlushFinalBlock(); - } + Array.Copy(aes.CreateDecryptor().TransformFinalBlock(src, srcIndex, src.Length), srcIndex, dest, destIndex, length); } } @@ -74,13 +62,7 @@ namespace LibHac aes.IV = iv; aes.Mode = CipherMode.CBC; aes.Padding = PaddingMode.None; - var dec = aes.CreateEncryptor(); - using (var ms = new MemoryStream(dest, destIndex, length)) - using (var cs = new CryptoStream(ms, dec, CryptoStreamMode.Write)) - { - cs.Write(src, srcIndex, length); - cs.FlushFinalBlock(); - } + Array.Copy(aes.CreateEncryptor().TransformFinalBlock(src, srcIndex, src.Length), srcIndex, dest, destIndex, length); } }