Skip to content

Instantly share code, notes, and snippets.

@khr0x40sh
Created March 23, 2023 18:36
Show Gist options
  • Save khr0x40sh/4c2744e8679a2d98c45a34347cf79b5f to your computer and use it in GitHub Desktop.
Save khr0x40sh/4c2744e8679a2d98c45a34347cf79b5f to your computer and use it in GitHub Desktop.
HTB:CA2023 Forensics Interstellar Encryption C2 Function
private static string Encryption(string key, string un, bool comp = false, byte[] unByte = null)
{
byte[] array = null;
if (unByte != null)
{
array = unByte;
}
else
{
array = Encoding.UTF8.GetBytes(un);
}
if (comp)
{
array = Program.Compress(array);
}
string result;
try
{
SymmetricAlgorithm symmetricAlgorithm = Program.CreateCam(key, null, true);
byte[] second = symmetricAlgorithm.CreateEncryptor().TransformFinalBlock(array, 0, array.Length);
result = Convert.ToBase64String(Program.Combine(symmetricAlgorithm.IV, second));
}
catch
{
SymmetricAlgorithm symmetricAlgorithm2 = Program.CreateCam(key, null, false);
byte[] second2 = symmetricAlgorithm2.CreateEncryptor().TransformFinalBlock(array, 0, array.Length);
result = Convert.ToBase64String(Program.Combine(symmetricAlgorithm2.IV, second2));
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment