opteryx icon indicating copy to clipboard operation
opteryx copied to clipboard

✨ Support Encryption for Parquet files

Open joocer opened this issue 1 year ago • 0 comments
trafficstars

This may require the data to be defined in Tarchia in order to get the encryption details. Tarchia already provides a mechanism to record column-level encryption information.

import pyarrow as pa
import pyarrow.parquet as pq

# Sample data
data = pa.table({
    'name': ['Alice', 'Bob', 'Charlie'],
    'age': [25, 30, 35],
    'salary': [50000, 60000, 70000]
})

# Define encryption properties
encryption_properties = pq.EncryptionConfiguration(
    key_material=b'0123456789abcdef0123456789abcdef'  # 32-byte key
)

# Write to encrypted Parquet file
pq.write_table(
    data,
    'encrypted_data.parquet',
    encryption_configuration=encryption_properties
)

# Define decryption properties
decryption_properties = pq.DecryptionConfiguration(
    key_material=b'0123456789abcdef0123456789abcdef'
)

# Read the encrypted Parquet file
table = pq.read_table('encrypted_data.parquet', decryption_configuration=decryption_properties)
print(table)

joocer avatar Jul 23 '24 16:07 joocer