mirror of
https://github.com/SabreTools/NDecrypt.git
synced 2026-09-21 22:35:03 +00:00
Reduce unnecessary methods
This commit is contained in:
@@ -19,7 +19,10 @@ namespace NDecrypt.Core
|
||||
/// <returns>Initialized AES cipher</returns>
|
||||
public static IBufferedCipher CreateAESDecryptionCipher(byte[] key, byte[] iv)
|
||||
{
|
||||
var keyParam = new KeyParameter(TakeSixteen(key));
|
||||
if (key.Length != 16)
|
||||
throw new ArgumentOutOfRangeException(nameof(key));
|
||||
|
||||
var keyParam = new KeyParameter(key);
|
||||
var cipher = CipherUtilities.GetCipher("AES/CTR");
|
||||
cipher.Init(forEncryption: false, new ParametersWithIV(keyParam, iv));
|
||||
return cipher;
|
||||
@@ -33,7 +36,10 @@ namespace NDecrypt.Core
|
||||
/// <returns>Initialized AES cipher</returns>
|
||||
public static IBufferedCipher CreateAESEncryptionCipher(byte[] key, byte[] iv)
|
||||
{
|
||||
var keyParam = new KeyParameter(TakeSixteen(key));
|
||||
if (key.Length != 16)
|
||||
throw new ArgumentOutOfRangeException(nameof(key));
|
||||
|
||||
var keyParam = new KeyParameter(key);
|
||||
var cipher = CipherUtilities.GetCipher("AES/CTR");
|
||||
cipher.Init(forEncryption: true, new ParametersWithIV(keyParam, iv));
|
||||
return cipher;
|
||||
@@ -118,18 +124,6 @@ namespace NDecrypt.Core
|
||||
progress($"{blockCount + 1} / {blockCount + 1} MB... Done!\r\n");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pad an array to 16 bytes
|
||||
/// </summary>
|
||||
/// <param name="input">Byte array value to pad</param>
|
||||
/// <returns>16-byte padded array</returns>
|
||||
internal static byte[] TakeSixteen(byte[] input)
|
||||
{
|
||||
var arr = new byte[16];
|
||||
Array.Copy(input, arr, Math.Min(input.Length, 16));
|
||||
return arr;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Byte Arrays
|
||||
|
||||
@@ -55,10 +55,7 @@ namespace NDecrypt.Core
|
||||
KeyX2C = development ? args.DevKeyX0x2C : args.KeyX0x2C;
|
||||
|
||||
// Backup headers can't have a KeyY value set
|
||||
if (signature != null)
|
||||
KeyY = TakeSixteen(signature);
|
||||
else
|
||||
KeyY = TakeSixteen(new byte[16]);
|
||||
KeyY = signature != null && signature.Length == 16 ? signature : new byte[16];
|
||||
|
||||
// Set the standard normal key values
|
||||
NormalKey = new byte[16];
|
||||
|
||||
Reference in New Issue
Block a user