public static void Demo() { // open input and output file streams Stream inputFile = File.OpenRead(".\\ResourceFiles\\userdata1.parquet"); Stream outputFile = File.OpenWrite(".\\ResourceFiles\\out1.parquet"); // Create reader using ParquetFileReader reader = new ParquetFileReader(inputFile); // Copy source settings as target settings List <FileEncryptionSettings> writerSettings = reader.FileEncryptionSettings .Select(s => Copy(s)) .ToList(); // Modify a few column settings writerSettings[0] = new FileEncryptionSettings <DateTimeOffset?>(encryptionKey, SqlSerializerFactory.Default.GetDefaultSerializer <DateTimeOffset?>()); writerSettings[3] = new FileEncryptionSettings <string>(encryptionKey, EncryptionType.Deterministic, new SqlVarcharSerializer(size: 255)); writerSettings[10] = new FileEncryptionSettings <double?>(encryptionKey, StandardSerializerFactory.Default.GetDefaultSerializer <double?>()); // Create and pass the target settings to the writer using ParquetFileWriter writer = new ParquetFileWriter(outputFile, writerSettings); // Process the file ColumnarCryptographer cryptographer = new ColumnarCryptographer(reader, writer); cryptographer.Transform(); Console.Clear(); }
protected IList <FileEncryptionSettings> LoadFileEncryptionSettings(DataProtectionConfig config, bool encrypted) { List <FileEncryptionSettings> encryptionSettings = new List <FileEncryptionSettings>(); for (int i = 0; i < header.Length; i++) { ColumnEncryptionInfo encryptionInfo = config.ColumnEncryptionInfo.Where(x => x.ColumnName == header[i]).FirstOrDefault(); if (encryptionInfo != null) { string dekName = encryptionInfo.ColumnKeyName; ColumnKeyInfo dekInfo = config.ColumnKeyInfo.First(x => x.Name == encryptionInfo.ColumnKeyName); byte[] dekBytes = Converter.FromHexString(dekInfo.EncryptedColumnKey); ColumnMasterKeyInfo kekInfo = config.ColumnMasterKeyInfo.First(x => x.Name == dekInfo.ColumnMasterKeyName); KeyEncryptionKey kek = new KeyEncryptionKey(kekInfo.Name, kekInfo.KeyPath, azureKeyProvider); EncryptionType encryptionType = EncryptionType.Plaintext; if (encrypted) { if (encryptionInfo.EncryptionType.ToLower() == "randomized") { encryptionType = EncryptionType.Randomized; } else if (encryptionInfo.EncryptionType.ToLower() == "deterministic") { encryptionType = EncryptionType.Deterministic; } else { encryptionType = EncryptionType.Plaintext; } } var encryptionSetting = new FileEncryptionSettings <string>(new ProtectedDataEncryptionKey(dekName, kek, dekBytes), encryptionType, new SqlVarCharSerializer(size: 255)); encryptionSettings.Add(encryptionSetting); } else { if (defaultKEK == null) { ColumnMasterKeyInfo kekInfo = config.ColumnMasterKeyInfo.First(); KeyEncryptionKey kek = new KeyEncryptionKey(kekInfo.Name, kekInfo.KeyPath, azureKeyProvider); defaultKEK = kek; } var encryptionSetting = new FileEncryptionSettings <string>(new ProtectedDataEncryptionKey("none", defaultKEK), EncryptionType.Plaintext, new SqlVarCharSerializer(size: 255)); encryptionSettings.Add(encryptionSetting); } } return(encryptionSettings); }
public static FileEncryptionSettings Copy(FileEncryptionSettings encryptionSettings) { Type genericType = encryptionSettings.GetType().GenericTypeArguments[0]; Type settingsType = typeof(FileEncryptionSettings <>).MakeGenericType(genericType); return((FileEncryptionSettings)Activator.CreateInstance( settingsType, new object[] { encryptionSettings.DataEncryptionKey, encryptionSettings.EncryptionType, encryptionSettings.GetSerializer() } )); }