Ejemplo n.º 1
0
        public void Aes_EncryptFile_Test()
        {
            //Arrange
            var tempPath = Path.GetTempPath();

            if (!Directory.Exists(tempPath))
            {
                Directory.CreateDirectory(tempPath);
            }
            var path         = $"{tempPath}Security.txt";
            var originalData = Resources.ResourceManager.GetString("Security");

            File.WriteAllText(path, originalData);

            var encryptedPath = $"{tempPath}Security.encrypt";
            var decryptPath   = $"{tempPath}security2.txt";
            var aes           = new AES256();

            //Act
            aes.EncryptFile(EncryptionKey, path, encryptedPath);
            aes.DecryptFile(EncryptionKey, encryptedPath, decryptPath);

            var inputFile  = File.ReadAllText(path);
            var outputFile = File.ReadAllText(decryptPath);

            //Assert
            Assert.AreEqual(inputFile, outputFile);

            File.Delete(path);
            File.Delete(encryptedPath);
            File.Delete(decryptPath);
        }
Ejemplo n.º 2
0
 private void EncryptFileOnUpload(String pathFile, String encryptionKey, Boolean isImage)
 {
     AES256.EncryptFile(pathFile, encryptionKey);
     if (isImage)
     {
         foreach (ImageFormat format in ImagesFormats)
         {
             String pathFileWithExtension = DocumentUtils.GetNewPathFileName(pathFile, format.Name);
             if (File.Exists(pathFileWithExtension))
             {
                 AES256.EncryptFile(pathFileWithExtension, encryptionKey);
             }
         }
     }
 }