public static async Task <byte[]> ExtractUserDataFile(string sourcePath, string destinationPath, byte[] key, byte[] iv) { NDirectory.CreateMissingDirs(destinationPath); await using var src = new FileStream(sourcePath, FileMode.Open, FileAccess.Read); await using var dest = new FileStream(destinationPath, FileMode.Create, FileAccess.Write); using var decryptor = QuickAesTransform.CreateDecryptor(key, iv); await using var srcCrypto = new CryptoStream(src, decryptor, CryptoStreamMode.Read); var hash = await srcCrypto.CopyToCreateHashAsync(dest); return(hash); }
public void MoveFile(UserDataFile file, string destination) { // TODO: check if destination is a path by ending with a / var relativePath = NPath.RemoveRelativeParts(destination); var prevFileName = file.Header.SecuredPlainName.PlainName; if (PlainNameAlreadyExists(relativePath)) { FileAlreadyExists(); } file.Move(relativePath); if (file.Header.IsUnlocked) { var srcPath = Path.Combine(UnlockedFolderPath, prevFileName); var destPath = Path.Combine(UnlockedFolderPath, file.Header.SecuredPlainName.PlainName); NDirectory.CreateMissingDirs(destPath); File.Move(srcPath, destPath); } }