C# 无法从AES解密c获取纯文本#

C# 无法从AES解密c获取纯文本#,c#,aes,C#,Aes,我正在尝试创建一个需要反向工程的CTF挑战 所以基本上我需要加密一个字符串,这样我知道一个纯文本的加密值。在本例中为“xor_标志”。一旦我有了它,我将擦除纯文本值,然后只使用解密函数。但现在,我只需要让encrpytion正常工作。我工作过的最接近的东西是:它以十六进制值显示纯文本 using System; using System.Collections.Generic; using System.Linq; using System.Security.Cryptography; usin

我正在尝试创建一个需要反向工程的CTF挑战

所以基本上我需要加密一个字符串,这样我知道一个纯文本的加密值。在本例中为“xor_标志”。一旦我有了它,我将擦除纯文本值,然后只使用解密函数。但现在,我只需要让encrpytion正常工作。我工作过的最接近的东西是:它以十六进制值显示纯文本

using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Threading;

namespace XorFlag2
{
class Program
{
    // USe de4dot on the .exe and use .net reflector on cleaned one,after de4dot finishes.
    // IN reflector go to main method

    //num var is what you need . For xoring you can use windows calculator(->scientific mode)
    // so: num xor 53129566096 must be = 65535655351
    // num is = 65535655351 xor 53129566096 (=13371337255)
    // start program type: 13371337255 ,hit enter and you 'll get the flag

    private static void Main(string[] args)
    {
        Console.WriteLine("Greetings challenger! Step right up and try your shot at gaining the flag!");
        Console.WriteLine("You'll have to know the pascode to unlock the prize:");
        long num = Convert.ToInt64(Console.ReadLine());
        if ((num ^ 53129566096L) == 65535655351L)
        {
            Console.WriteLine("yay");
        }
        else
        {
            Console.WriteLine("Incorrect, try again!");
        }

            byte[] iV = new byte[] { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 };
            byte[] array = new byte[16];
            BitConverter.GetBytes(num).CopyTo(array, 0);
            BitConverter.GetBytes(num).CopyTo(array, 8);
            string s = "ls/5RTxwflDrqr5G8pO9cQ1NlgQcFjcJj9x4z7oIhlfY4w42GAFqKbyzwqHAZQBZa5ctysKKWIbTgU2VxoR​YohxCbPyV6sEU/tn+sIxNg6A/r5OJnIMqTs0seMrzWh5J";
            string t = "flag_xor";
            byte[] encrypted = EncryptStringToBytes(t, array, iV);
            Console.WriteLine(BitConverter.ToString(encrypted));
           // str = DecryptStringFromBytes(Convert.FromBase64String(t), array, iV);
          //  Console.WriteLine(str);

       // catch (Exception exception)
        //{
           // Console.WriteLine("ERROR!!! darn. huh? how did I get here? Hmm, something must have gone wrong. What am I doing?", exception);
        //}
        Console.WriteLine("press key to continue");
        Console.ReadKey();
    }

    static string DecryptStringFromBytes(byte[] cipherText, byte[] Key, byte[] IV)
    {

        // Check arguments. 
        if (cipherText == null || cipherText.Length <= 0)
            throw new ArgumentNullException("cipherText");
        if (Key == null || Key.Length <= 0)
            throw new ArgumentNullException("Key");
        if (IV == null || IV.Length <= 0)
            throw new ArgumentNullException("Key");

        // Declare the string used to hold 
        // the decrypted text. 
        string plaintext = null;

        // Create an RijndaelManaged object 
        // with the specified key and IV. 
        using (RijndaelManaged rijAlg = new RijndaelManaged())
        {
            rijAlg.Key = Key;
            rijAlg.IV = IV;
            rijAlg.Padding = PaddingMode.None;

            // Create a decrytor to perform the stream transform.
            ICryptoTransform decryptor = rijAlg.CreateDecryptor(rijAlg.Key, rijAlg.IV);

            // Create the streams used for decryption. 
            using (MemoryStream msDecrypt = new MemoryStream(cipherText))
            {
                using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
                {
                    using (StreamReader srDecrypt = new StreamReader(csDecrypt))
                    {

                        // Read the decrypted bytes from the decrypting stream 
                        // and place them in a string.
                        plaintext = srDecrypt.ReadToEnd();
                    }
                }
            }

        }

        return plaintext;

    }

    static byte[] EncryptStringToBytes(string plainText, byte[] Key, byte[] IV)
    {
        // Check arguments. 
        if (plainText == null || plainText.Length <= 0)
            throw new ArgumentNullException("plainText");
        if (Key == null || Key.Length <= 0)
            throw new ArgumentNullException("Key");
        if (IV == null || IV.Length <= 0)
            throw new ArgumentNullException("Key");
        byte[] encrypted;
        // Create an RijndaelManaged object 
        // with the specified key and IV. 
        using (RijndaelManaged rijAlg = new RijndaelManaged())
        {
            rijAlg.Key = Key;
            rijAlg.IV = IV;

            // Create a decrytor to perform the stream transform.
            ICryptoTransform encryptor = rijAlg.CreateEncryptor(rijAlg.Key, rijAlg.IV);

            // Create the streams used for encryption. 
            using (MemoryStream msEncrypt = new MemoryStream())
            {
                using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
                {
                    using (StreamWriter swEncrypt = new StreamWriter(csEncrypt))
                    {

                        //Write all data to the stream.
                        swEncrypt.Write(plainText);
                    }
                    encrypted = msEncrypt.ToArray();
                }
            }
        }


        // Return the encrypted bytes from the memory stream. 
        return encrypted;

    }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Security.Cryptography;
使用系统文本;
使用System.Threading.Tasks;
使用System.IO;
使用系统线程;
命名空间XorFlag2
{
班级计划
{
//de4dot完成后,在.exe上使用de4dot,在清洁的一个上使用.net reflector。
//在反射器中,转到主方法
//num var是您所需要的。对于xoring,您可以使用windows计算器(->科学模式)
//所以:num xor 53129566096必须是=65535655351
//num is=65535655351异或53129566096(=1337137255)
//启动程序类型:1337137255,点击回车键,您将获得标志
私有静态void Main(字符串[]args)
{
控制台。WriteLine(“你好,挑战者!马上站起来,试着获得旗帜!”);
WriteLine(“你必须知道密码才能解锁奖品:”;
long num=Convert.ToInt64(Console.ReadLine());
如果((数值^53129566096L)==65535655351L)
{
控制台写入线(“yay”);
}
其他的
{
控制台。WriteLine(“不正确,再试一次!”);
}
byte[]iV=新字节[]{255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255};
字节[]数组=新字节[16];
BitConverter.GetBytes(num).CopyTo(数组,0);
位转换器.GetBytes(num).CopyTo(数组,8);
字符串s=“ls/5RTXWFLDRQR5G8PO9CQ1NLGQCFJCJ9X4Z7OIHLFY4W42GAFQKBYZWQHAZQBZA5CTYSKWIBTGU2VxOR​YohxCbPyV6sEU/tn+sIxNg6A/r5OJnIMqTs0seMrzWh5J”;
字符串t=“flag\u xor”;
字节[]加密=加密字符串字节(t,数组,iV);
Console.WriteLine(位转换器.ToString(加密));
//str=DecryptStringFromBytes(Convert.FromBase64String(t),数组,iV);
//控制台写入线(str);
//捕获(异常)
//{
//Console.WriteLine(“错误!!!该死的,嗯?我怎么到这里来的?嗯,一定是出了什么问题。我在干什么?”例外);
//}
Console.WriteLine(“按键继续”);
Console.ReadKey();
}
静态字符串解密StringFromBytes(字节[]密文,字节[]密钥,字节[]IV)
{
//检查参数。

如果(cipherText==null | | cipherText.Length您需要问一个问题请看:…答案中有一些方法将加密字节作为字符串返回。decrypt方法将加密字符串返回非加密字符串。您看到了吗?是的,我看到了,但我现在只想运行Encryption,然后存储加密字符串输入一个字符串,然后删除我的明文。