コード例 #1
0
        public IActionResult DecryptionText(string cryptomsg, string key)
        {
            myclass          op  = new myclass();
            Decryption_Class op2 = new Decryption_Class();


            string str = op2.BinaryToString(op2.convert_DNA_to_binary(op2.convert_finalDNA_to_DNA(op2.split_DNA(cryptomsg))));

            op.orignalmsg = XXTEA.Decrypt(str, key);
            //decryption
            // op.cryptomsg = XXTEA.Decrypt(orignalmsg, key);
            string document = op.orignalmsg;
            //decryption
            // op.cryptomsg = XXTEA.Decrypt(orignalmsg, key);
            //create file or put Encrypt message in file
            //path which file put in
            string path_Root = _hosting.WebRootPath;
            string docPath   = path_Root + "\\files\\";

            // Write the specified text asynchronously to a new file named "WriteTextAsync.txt".
            using (StreamWriter outputFile = new StreamWriter(Path.Combine(docPath, "Decryptmessage.txt")))
            {
                outputFile.Write(document);
            }

            return(View("DecryptionText", op));
        }
コード例 #2
0
        //Decryption file
        public IActionResult DecryptionFile(IFormFile File, string key)
        {
            fileclass        op  = new fileclass();
            Decryption_Class op2 = new Decryption_Class();

            if (File == null || File.Length == 0)
            {
                return(Content("file not selected"));
            }
            //get path
            string path_Root     = _hosting.WebRootPath;
            string path_to_files = path_Root + "\\files\\" + File.FileName;

            //copyfiles
            using (var stream = new FileStream(path_to_files, FileMode.Create))
            {
                File.CopyTo(stream);
            }



            // read file
            FileStream fileStream = new FileStream(path_to_files, FileMode.Open);

            using (StreamReader reader = new StreamReader(fileStream))
            {
                // string line = reader.ReadLine();
                string line = reader.ReadToEnd();
                //  op.Encryptfile = line;
                string str = op2.BinaryToString(op2.convert_DNA_to_binary(op2.convert_finalDNA_to_DNA(op2.split_DNA(line))));
                op.Decryptfile = XXTEA.Decrypt(str, key);
            }
            downloadtext = op.Decryptfile;
            //delete file
            FileInfo fi = new FileInfo(path_to_files);

            if (fi != null)
            {
                System.IO.File.Delete(path_to_files);
                fi.Delete();
            }
            ///////////////////
            //create file or put Encrypt message in file
            //path which file put in
            string docPath = path_Root + "\\files\\";

            // Write the specified text asynchronously to a new file named "WriteTextAsync.txt".
            using (StreamWriter outputFile = new StreamWriter(Path.Combine(docPath, "Decryptmessage.txt")))
            {
                outputFile.Write(downloadtext);
            }

            return(View("DecryptionFile", op));
        }