Exemplo n.º 1
0
        public HttpResponseMessage GetAES(string option)
        {
            Encryption encryption = new Encryption();

            if (option == "encrypt")
            {
                encryption.EncryptFile(PathFile, PathFile + "enc", "password");
            }
            else if (option == "decrypt")
            {
                encryption.DecryptFile(PathFile + "enc", PathFile, "password");

            }

            HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
            var stream = new FileStream(PathFile + "enc", FileMode.Open);
            result.Content = new StreamContent(stream);
            result.Content.Headers.ContentType =
                new MediaTypeHeaderValue("application/octet-stream");

            return result;
        }
        public HttpResponseMessage GetAES(string option, string password)
        {
            Encryption encryption = new Encryption();

            if (option == "encrypt")
            {
                encryption.EncryptFile(PathFile, PathFile + "enc", password);
            }
            else if (option == "decrypt")
            {
                try
                {
                    encryption.DecryptFile(PathFile + "enc", PathFile, password);
                }
                catch (CryptographicException e)
                {
                    return new HttpResponseMessage(HttpStatusCode.BadRequest);
                }

            }

            HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
            Stream stream;
            if (option == "encrypt")
            {
                stream = new FileStream(PathFile + "enc", FileMode.Open);

            } else
            {
                stream = new FileStream(PathFile, FileMode.Open);

            }
            result.Content = new StreamContent(stream);
            result.Content.Headers.ContentType =
                new MediaTypeHeaderValue("application/octet-stream");

            return result;
        }
Exemplo n.º 3
0
 static void Main(string[] args)
 {
     Encryption encryption = new Encryption();
     encryption.DecryptFile("plik.txt", null, "abcd");
 }
Exemplo n.º 4
0
 public void PasswordIsNull_DecryptFile()
 {
     Encryption encryption = new Encryption();
     encryption.DecryptFile("plik.txt", "encrypted.txt", null);
 }
Exemplo n.º 5
0
 public void FilePathIsNull_DecryptFile()
 {
     Encryption encryption = new Encryption();
     encryption.DecryptFile("plik.txt", null, "abc");
 }