예제 #1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         string    message = xmlCommonUtil.QueryString["msg"];
         AESCipher aes     = new AESCipher("427d0a5839078c2ba379ecc9772aefa8");
         string    dec     =
             aes.Decrypt(message);
         xmlCommonUtil.ResponseWriteErrorMSG(dec);
     }
 }
        public string SolveChallenge()
        {
            AESCipher aes = new AESCipher(CipherMode.ECB, PaddingMode.None);

            return(aes.Decrypt(new CipherText(_cipherText, CipherTextFormat.BASE64), _key));
        }
예제 #3
0
        static void Main(string[] args)
        {
            if (!ParseInput(args))
            {
                return;
            }

            if (Params.verbose)
            {
                System.Console.WriteLine(Params.decrypt ? "Running in decryption mode." : "Running in endryption mode.");
                System.Console.WriteLine(Params.useCBC ? "Using CBC." : "Using ECB.");
                System.Console.WriteLine(Params.usePadding ? "Using PKCS5 padding." : "Not using padding. (Will fail if text length is not mod 16 byte.)");

                System.Console.WriteLine("Key: ({0})", Params.key);
                System.Console.WriteLine(BytesToFormatedString(Encoding.UTF8.GetBytes(Params.key)));
                System.Console.WriteLine();

                System.Console.WriteLine("Text: '{0}'", Params.text);
                System.Console.WriteLine(BytesToFormatedString(Encoding.UTF8.GetBytes(Params.text)));
                System.Console.WriteLine();
            }

            var cipher = new AESCipher(
                new AESParameters(
                    Encoding.UTF8.GetBytes(Params.key),
                    Params.keySize,
                    Params.useCBC,
                    Params.usePadding,
                    Params.useKeyPadding,
                    Encoding.UTF8.GetBytes(Params.initVector),
                    Params.verbose
                    )
                );

            byte[] result;

            if (Params.decrypt)
            {
                result = cipher.Decrypt(Convert.FromBase64String(Params.text));
            }
            else
            {
                result = cipher.Encrypt(Encoding.UTF8.GetBytes(Params.text));
            }

            if (Params.hex)
            {
                if (Params.useLabels || Params.verbose)
                {
                    System.Console.WriteLine("Result (Hex):");
                }
                System.Console.WriteLine(BytesToFormatedString(result));
            }

            if (Params.base64)
            {
                if (Params.useLabels || Params.verbose)
                {
                    System.Console.WriteLine("Result (base64):");
                }
                System.Console.WriteLine(Convert.ToBase64String(result));
            }

            if (Params.decrypt)
            {
                if (Params.useLabels || Params.verbose)
                {
                    System.Console.WriteLine("Result (utf-8):");
                }
                System.Console.WriteLine(Encoding.UTF8.GetString(result));
            }
        }