Esempio n. 1
0
 private static void EncryptEachFileWithPassword(string[] filePaths, byte[] salt, byte[] keyEncryptionKey)
 {
     foreach (string inputFilePath in filePaths)
     {
         bool validFilePath = FilePathValidation.FileEncryption(inputFilePath);
         if (!validFilePath)
         {
             --Globals.TotalCount;
             continue;
         }
         // Fill the ephemeral public key header with random bytes (since not in use)
         byte[] randomEphemeralPublicKeyHeader = Generate.EphemeralPublicKeyHeader();
         string outputFilePath = FileEncryption.GetOutputFilePath(inputFilePath);
         EncryptInputFile(inputFilePath, outputFilePath, randomEphemeralPublicKeyHeader, salt, keyEncryptionKey);
     }
     Utilities.ZeroArray(keyEncryptionKey);
 }
Esempio n. 2
0
 private static void EncryptEachFileWithPassword(string[] filePaths, byte[] salt, byte[] keyEncryptionKey)
 {
     foreach (string inputFilePath in filePaths)
     {
         bool validFilePath = FilePathValidation.FileEncryption(inputFilePath);
         if (!validFilePath)
         {
             --Globals.TotalCount;
             continue;
         }
         // Fill unused header with random public key
         byte[] ephemeralPublicKey = Generate.EphemeralPublicKeyHeader();
         string outputFilePath     = FileEncryption.GetOutputFilePath(inputFilePath);
         EncryptInputFile(inputFilePath, outputFilePath, ephemeralPublicKey, salt, keyEncryptionKey);
     }
     CryptographicOperations.ZeroMemory(keyEncryptionKey);
 }
Esempio n. 3
0
 private static void EncryptEachFileWithPrivateKey(string[] filePaths, byte[] privateKey)
 {
     foreach (string inputFilePath in filePaths)
     {
         bool validFilePath = FilePathValidation.FileEncryption(inputFilePath);
         if (!validFilePath)
         {
             --Globals.TotalCount;
             continue;
         }
         // Derive a unique KEK per file
         byte[] ephemeralSharedSecret = KeyExchange.GetPrivateKeySharedSecret(privateKey, out byte[] ephemeralPublicKey);
         byte[] salt             = Generate.Salt();
         byte[] keyEncryptionKey = Generate.KeyEncryptionKey(ephemeralSharedSecret, salt);
         string outputFilePath   = FileEncryption.GetOutputFilePath(inputFilePath);
         EncryptInputFile(inputFilePath, outputFilePath, ephemeralPublicKey, salt, keyEncryptionKey);
         CryptographicOperations.ZeroMemory(keyEncryptionKey);
     }
 }
Esempio n. 4
0
 private static void EncryptEachFileWithPublicKey(string[] filePaths, byte[] sharedSecret, byte[] recipientPublicKey)
 {
     foreach (string inputFilePath in filePaths)
     {
         bool validFilePath = FilePathValidation.FileEncryption(inputFilePath);
         if (!validFilePath)
         {
             --Globals.TotalCount;
             continue;
         }
         // Derive a unique KEK per file
         (byte[] ephemeralSharedSecret, byte[] ephemeralPublicKey) = KeyExchange.GetEphemeralSharedSecret(recipientPublicKey);
         byte[] salt             = Generate.Salt();
         byte[] keyEncryptionKey = Generate.KeyEncryptionKey(sharedSecret, ephemeralSharedSecret, salt);
         string outputFilePath   = FileEncryption.GetOutputFilePath(inputFilePath);
         EncryptInputFile(inputFilePath, outputFilePath, ephemeralPublicKey, salt, keyEncryptionKey);
         Utilities.ZeroArray(keyEncryptionKey);
     }
 }