mirror of
https://github.com/riegera2412/UVtools.git
synced 2026-07-09 01:52:32 +02:00
Initial pass at Encrypted CTB format support for UVTools
Helpers.cs: Added new SHA256 and AES helper methods FileFormat.cs: Add as available file format, does not appear in the UI CTBEncryptedFile.cs: New FileFormat implementation for these encrypted CTB files. Keys are left as an excercise
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -278,6 +278,7 @@ namespace UVtools.Core.FileFormats
|
||||
new SL1File(), // Prusa SL1
|
||||
new ChituboxZipFile(), // Zip
|
||||
new ChituboxFile(), // cbddlp, cbt, photon
|
||||
new CTBEncryptedFile(), // Mars 3, Epax 5k
|
||||
new PhotonSFile(), // photons
|
||||
new PHZFile(), // phz
|
||||
new FDGFile(), // fdg
|
||||
|
||||
@@ -57,6 +57,47 @@ namespace UVtools.Core
|
||||
return Convert.ToBase64String(SHA1.ComputeHash(input));
|
||||
}
|
||||
|
||||
public static SHA256 SHA256 { get; } = SHA256.Create();
|
||||
public static byte[] ComputeSHA256Hash(byte[] input)
|
||||
{
|
||||
return SHA256.ComputeHash(input);
|
||||
}
|
||||
|
||||
public static byte[] AesCryptBytes(byte[] data, byte[] key, CipherMode mode, PaddingMode paddingMode, bool encrypt, byte[] iv = null)
|
||||
{
|
||||
if (data.Length % 0x10 != 0)
|
||||
{
|
||||
byte[] temp = new byte[((data.Length / 0x10) + 1) * 0x10];
|
||||
Array.Copy(data, 0, temp, 0, data.Length);
|
||||
data = temp;
|
||||
}
|
||||
|
||||
|
||||
AesManaged aes = new AesManaged();
|
||||
|
||||
aes.KeySize = key.Length * 8;
|
||||
aes.Key = key;
|
||||
aes.Padding = paddingMode;
|
||||
aes.Mode = mode;
|
||||
if (iv != null)
|
||||
{
|
||||
aes.IV = iv;
|
||||
}
|
||||
ICryptoTransform cryptor = encrypt ? aes.CreateEncryptor() : aes.CreateDecryptor();
|
||||
|
||||
byte[] outputBuffer = null;
|
||||
using (MemoryStream msDecrypt = new MemoryStream(data))
|
||||
{
|
||||
using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, cryptor, CryptoStreamMode.Read))
|
||||
{
|
||||
outputBuffer = new byte[data.Length];
|
||||
csDecrypt.Read(outputBuffer, 0, data.Length);
|
||||
}
|
||||
}
|
||||
|
||||
return outputBuffer;
|
||||
}
|
||||
|
||||
public static bool SetPropertyValue(PropertyInfo attribute, object obj, string value)
|
||||
{
|
||||
var name = attribute.PropertyType.Name.ToLower();
|
||||
|
||||
Reference in New Issue
Block a user