示例#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;
        }
示例#3
0
 public void PasswordIsNull_EncryptFile()
 {
     Encryption encryption = new Encryption();
     encryption.EncryptFile("plik.txt", "encrypted.txt", null);
 }
示例#4
0
 public void FilePathIsNull_EncryptFile()
 {
     Encryption encryption = new Encryption();
     encryption.EncryptFile(null, "encrypted.txt", "password");
 }
示例#5
0
 public void EncryptedFilePathIsNull_EncryptFile()
 {
     Encryption encryption = new Encryption();
     encryption.EncryptFile("plik.txt", null, "password");
 }