/// <summary> /// Encrypts a password file at the specified path. /// If the path contains directories that do not exist, they will be created automatically. /// </summary> /// <param name="file"> /// A <see cref="KeyedPasswordFile"/> instance specifying the contents /// of the password file to be encrypted. /// </param> /// <param name="overwrite"> /// If this file already exists, should it be overwritten? /// </param> public PasswordFile EncryptPassword(DecryptedPasswordFile file, bool overwrite) { file.Directory.Create(); if (overwrite && file.FileInfo.Exists) { file.FileInfo.Delete(); } Crypto.Encrypt(file.Content, file.FullPath, GetGpgIds(file.FullPath)); return(new PasswordFile(file.PasswordStore, file.RelativePath)); }
private PasswordFile EncryptPasswordInternal(DecryptedPasswordFile file, bool overwrite) { file.Directory.Create(); if (file.FileInfo.Exists) { if (overwrite) { file.FileInfo.Delete(); } else { throw new InvalidOperationException("A password file already exists at the specified location."); } } cryptoService.Encrypt(file.Content, file.FullPath, recipientFinder.FindRecipients(file)); return(new PasswordFile(file)); }
/// <summary> /// Encrypts a password file at the specified path. /// If the path contains directories that do not exist, they will be created automatically. /// </summary> /// <param name="file"> /// A <see cref="KeyedPasswordFile"/> instance specifying the contents /// of the password file to be encrypted. /// </param> public PasswordFile EncryptPassword(DecryptedPasswordFile file) { return(EncryptPasswordInternal(file, true)); }