mirror of
https://silica.codes/BedrockReverse/PremiumPacksInstaller.git
synced 2025-04-21 20:25:56 +12:00
Upload v1.0
This commit is contained in:
parent
02a911de75
commit
b3a80a479a
46 changed files with 76594 additions and 0 deletions
73
LibMcCrypt/Crypto.cs
Normal file
73
LibMcCrypt/Crypto.cs
Normal file
|
@ -0,0 +1,73 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace McCrypt
|
||||
{
|
||||
internal class Crypto
|
||||
{
|
||||
internal static byte[] Sha256(byte[] data)
|
||||
{
|
||||
SHA256 sha256 = SHA256.Create();
|
||||
byte[] hash = sha256.ComputeHash(data);
|
||||
sha256.Dispose();
|
||||
return hash;
|
||||
}
|
||||
internal static byte[] Aes256CfbEncrypt(byte[] key, byte[] iv, byte[] data)
|
||||
{
|
||||
Aes aes = Aes.Create();
|
||||
aes.Mode = CipherMode.CFB;
|
||||
aes.Padding = PaddingMode.None;
|
||||
aes.BlockSize = 128;
|
||||
aes.KeySize = 256;
|
||||
|
||||
ICryptoTransform aesEncryptor = aes.CreateEncryptor(key, iv);
|
||||
using (MemoryStream msEncrypt = new MemoryStream())
|
||||
{
|
||||
using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, aesEncryptor, CryptoStreamMode.Write))
|
||||
{
|
||||
csEncrypt.Write(data, 0, data.Length);
|
||||
|
||||
long totalWritten = data.Length;
|
||||
while ((totalWritten % 16 != 0))
|
||||
{
|
||||
csEncrypt.WriteByte(0);
|
||||
totalWritten++;
|
||||
}
|
||||
|
||||
msEncrypt.Seek(0x00, SeekOrigin.Begin);
|
||||
return msEncrypt.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static byte[] Aes256CfbDecrypt(byte[] key, byte[] iv, byte[] data)
|
||||
{
|
||||
Aes aes = Aes.Create();
|
||||
aes.Mode = CipherMode.CFB;
|
||||
aes.Padding = PaddingMode.Zeros;
|
||||
aes.BlockSize = 128;
|
||||
aes.KeySize = 256;
|
||||
|
||||
ICryptoTransform aesDecryptor = aes.CreateDecryptor(key, iv);
|
||||
using (MemoryStream msDecrypt = new MemoryStream())
|
||||
{
|
||||
msDecrypt.Write(data, 0, data.Length);
|
||||
|
||||
while (msDecrypt.Length % 16 != 0)
|
||||
msDecrypt.WriteByte(0);
|
||||
|
||||
msDecrypt.Seek(0x00, SeekOrigin.Begin);
|
||||
using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, aesDecryptor, CryptoStreamMode.Read))
|
||||
{
|
||||
byte[] plaintext = new byte[msDecrypt.Length];
|
||||
csDecrypt.Read(plaintext, 0x00, plaintext.Length);
|
||||
|
||||
Array.Copy(plaintext, data, data.Length);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue