/// <summary> /// Encrypts by loading inputFile to a string and then encrypting the string. String is then written out as text to the encryptedOutputFile. /// </summary> /// <param name="inputFile">Full path to file that will be encrypted.</param> /// <param name="encryptedOutputFile">Full path to file that will contain encrypted data.</param> /// <returns>Returns path to encrypted output file.</returns> public string Encrypt(string inputFile, string encryptedOutputFile) { IStringEncryptor encryptor = new StringEncryptorTripleDES(); if (String.IsNullOrEmpty(inputFile) || String.IsNullOrEmpty(encryptedOutputFile)) { throw new ArgumentNullException("Paths to both input and encrypted output file need to specified."); } if (KeyIsValid(GetStringFromByteArray(_key)) == false) { throw new System.Exception("Invalid length for Key."); } if (IVIsValid(GetStringFromByteArray(_iv)) == false) { throw new System.Exception("Invalid length for IV."); } try { string data = File.ReadAllText(inputFile); encryptor.Key = this.Key; encryptor.IV = this.IV; string encryptedData = encryptor.Encrypt(data); File.WriteAllText(encryptedOutputFile, encryptedData); } catch (System.Exception ex) { _msg.Length = 0; _msg.Append("Attempt to encrypt file "); _msg.Append(inputFile); _msg.Append(" failed with following message: "); _msg.Append("\r\n"); _msg.Append(AppMessages.FormatErrorMessage(ex)); throw new System.Exception(_msg.ToString()); } finally { ; } return(encryptedOutputFile); }