public static void CallEncryption(bool encryption, char[] password, string keyfilePath, string[] filePaths) { byte[] passwordBytes = FileEncryption.GetPasswordBytes(password); Utilities.ZeroArray(password); FileEncryption.StartEncryption(encryption, filePaths, passwordBytes, keyfilePath); EncryptionCompleted(encryption); }
private static void EncryptInputFile(string inputFilePath, string outputFilePath, byte[] ephemeralPublicKey, byte[] salt, byte[] keyEncryptionKey) { try { EncryptFile.Initialize(inputFilePath, outputFilePath, ephemeralPublicKey, salt, keyEncryptionKey); FileEncryption.EncryptionSuccessful(inputFilePath, outputFilePath); } catch (Exception ex) when(ExceptionFilters.Cryptography(ex)) { DisplayMessage.FilePathException(inputFilePath, ex.GetType().Name, "Unable to encrypt the file."); } }
private static void FileEncryptionWithPrivateKey(string privateKeyPath, string[] filePaths) { bool validUserInput = FileEncryptionValidation.FileEncryptionWithPrivateKey(privateKeyPath, filePaths); if (!validUserInput) { return; } byte[] privateKey = AsymmetricKeyValidation.EncryptionPrivateKeyFile(privateKeyPath); if (privateKey == null) { return; } FileEncryption.EncryptEachFileWithPrivateKey(filePaths, privateKey); }
private static void FileEncryptionWithPassword(char[] password, string keyfilePath, string[] filePaths) { bool validUserInput = FileEncryptionValidation.FileEncryptionWithPassword(password, keyfilePath, filePaths); if (!validUserInput) { return; } if (!File.Exists(keyfilePath)) { keyfilePath = FilePathValidation.KeyfilePath(keyfilePath); } byte[] passwordBytes = Password.Hash(password, keyfilePath); FileEncryption.EncryptEachFileWithPassword(filePaths, passwordBytes); }
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); }
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); }
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); } }
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); } }
private static void FileEncryptionWithPublicKey(string senderPrivateKeyPath, char[] recipientPublicKeyString, string[] filePaths) { bool validUserInput = FileEncryptionValidation.FileEncryptionWithPublicKey(senderPrivateKeyPath, recipientPublicKeyString, filePaths); if (!validUserInput) { return; } byte[] senderPrivateKey = AsymmetricKeyValidation.EncryptionPrivateKeyFile(senderPrivateKeyPath); if (senderPrivateKey == null) { return; } byte[] recipientPublicKey = AsymmetricKeyValidation.EncryptionPublicKeyString(recipientPublicKeyString); if (recipientPublicKey == null) { return; } FileEncryption.EncryptEachFileWithPublicKey(filePaths, senderPrivateKey, recipientPublicKey); }
private static void GetBenchmarkInputs(out byte[] passwordBytes, out byte[] salt) { char[] password = "******".ToCharArray(); passwordBytes = FileEncryption.GetPasswordBytes(password); salt = Generate.Salt(); }