diff --git a/NDecrypt.Core/CommonOperations.cs b/NDecrypt.Core/CommonOperations.cs
index 73e5bd0..2ce0d35 100644
--- a/NDecrypt.Core/CommonOperations.cs
+++ b/NDecrypt.Core/CommonOperations.cs
@@ -19,7 +19,10 @@ namespace NDecrypt.Core
/// Initialized AES cipher
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
/// Initialized AES cipher
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");
}
- ///
- /// Pad an array to 16 bytes
- ///
- /// Byte array value to pad
- /// 16-byte padded array
- 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
diff --git a/NDecrypt.Core/PartitionKeys.cs b/NDecrypt.Core/PartitionKeys.cs
index 8b84b4f..605dc83 100644
--- a/NDecrypt.Core/PartitionKeys.cs
+++ b/NDecrypt.Core/PartitionKeys.cs
@@ -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];