Ejemplo n.º 1
0
        public Task <IActionResult> CipherRSA([FromForm] RSARequest obj)
        {
            if (obj.File.Length > 0)
            {
                if (!Directory.Exists(_environment.WebRootPath + "\\Cipher2\\"))
                {
                    Directory.CreateDirectory(_environment.WebRootPath + "\\Cipher2\\");
                }
                using var _fileStream = System.IO.File.Create(_environment.WebRootPath + "\\Cipher2\\" + obj.File.FileName);
                obj.File.CopyTo(_fileStream);
                _fileStream.Flush();
                _fileStream.Close();
                string FilePrivate = "PrivateKey.txt";

                if (!Directory.Exists(_environment.WebRootPath + "\\Cipher2\\"))
                {
                    Directory.CreateDirectory(_environment.WebRootPath + "\\Cipher2\\");
                }
                using var _fileStreamPrivate = System.IO.File.Create(_environment.WebRootPath + "\\Cipher2\\" + FilePrivate);
                _fileStreamPrivate.Flush();
                _fileStreamPrivate.Close();
                caesar.Cipher(_environment.WebRootPath + "\\Cipher2\\" + obj.File.FileName, obj.Key, _environment.WebRootPath + "\\Cipher2\\" + obj.Name + ".txt");
                rsa.GeneratePrivateKey(obj.P, obj.Q, obj.Key, _environment.WebRootPath + "\\Cipher2\\" + FilePrivate);

                return(DownloadZIP());
            }

            return(null);
        }
Ejemplo n.º 2
0
        public Task <IActionResult> CipherCaesar([FromForm] CipherCaesarRequest CipherCaesarRequest)
        {
            if (CipherCaesarRequest.File.Length > 0)
            {
                if (!Directory.Exists(_environment.WebRootPath + "\\Cipher\\"))
                {
                    Directory.CreateDirectory(_environment.WebRootPath + "\\Cipher\\");
                }
                using var _fileStream = System.IO.File.Create(_environment.WebRootPath + "\\Cipher\\" + CipherCaesarRequest.File.FileName);
                CipherCaesarRequest.File.CopyTo(_fileStream);
                _fileStream.Flush();
                _fileStream.Close();

                CaesarCipher.Cipher(_environment.WebRootPath + "\\Cipher\\" + "Alphabet.txt", _environment.WebRootPath + "\\Cipher\\" + CipherCaesarRequest.File.FileName, CipherCaesarRequest.Key, _environment.WebRootPath + "\\Cipher\\" + CipherCaesarRequest.Name + ".txt");
                return(GetFile(Convert.ToString(CipherCaesarRequest.Name), "\\Cipher\\"));
            }

            return(null);
        }