@@ -749,12 +749,29 @@ cdef shared_ptr[CDecryptionConfiguration] pyarrow_unwrap_decryptionconfig(object
749749 raise TypeError (" Expected DecryptionConfiguration, got %s " % type (decryptionconfig))
750750
751751
752+ cdef _validate_column_keys(column_keys):
753+ if not isinstance (column_keys, dict ):
754+ raise TypeError (" column_keys must be a dict of column paths to bytes" )
755+ if not column_keys:
756+ raise ValueError (" column_keys must not be empty" )
757+ for column_path, key in column_keys.items():
758+ if not isinstance (column_path, str ):
759+ raise TypeError (" column paths in column_keys must be strings" )
760+ if not column_path:
761+ raise ValueError (" column paths in column_keys must not be empty" )
762+ if not isinstance (key, bytes):
763+ raise TypeError (" column keys must be bytes" )
764+ if len (key) not in (16 , 24 , 32 ):
765+ raise ValueError (" column keys must be 16, 24, or 32 bytes" )
766+
767+
752768def create_decryption_properties (
753769 footer_key ,
754770 *,
755771 aad_prefix = None ,
756772 bint check_footer_integrity = True ,
757773 bint allow_plaintext_files = False ,
774+ column_keys = None ,
758775):
759776 """
760777 Create FileDecryptionProperties using a direct footer key.
@@ -769,18 +786,12 @@ def create_decryption_properties(
769786 Parquet key management specification and is interoperable with
770787 other tools and frameworks.
771788
772- .. note::
773- Currently only uniform encryption (single key for footer and all
774- columns) is supported with this method. Per-column keys are not
775- yet available; files encrypted with per-column keys cannot be
776- decrypted using this function.
777-
778789 Parameters
779790 ----------
780791 footer_key : bytes
781- The decryption key for the file footer and all columns (uniform
782- encryption) . Must be 16, 24, or 32 bytes for AES-128, AES-192 ,
783- or AES-256 respectively.
792+ The decryption key for the file footer and any columns encrypted
793+ with the footer key . Must be 16, 24, or 32 bytes for AES-128,
794+ AES-192, or AES-256 respectively.
784795 aad_prefix : bytes, optional
785796 Additional Authenticated Data prefix. Must match the AAD prefix
786797 that was used during encryption. Required if the AAD prefix was
@@ -791,6 +802,12 @@ def create_decryption_properties(
791802 allow_plaintext_files : bool, default False
792803 Whether to allow reading plaintext (unencrypted) files with
793804 these decryption properties without raising an error.
805+ column_keys : dict[str, bytes], optional
806+ Explicit keys for encrypted columns, mapped by their full Parquet
807+ column paths (dot-separated for nested fields). Keys must be 16, 24,
808+ or 32 bytes. Only columns read need to have keys supplied. Columns
809+ encrypted with the footer key continue to use ``footer_key``.
810+ An empty dictionary is not allowed.
794811
795812 Returns
796813 -------
@@ -814,6 +831,11 @@ def create_decryption_properties(
814831 CSecureString c_footer_key
815832 CFileDecryptionPropertiesBuilder builder
816833 shared_ptr[CFileDecryptionProperties] props
834+ c_map[c_string, shared_ptr[CColumnDecryptionProperties]] c_column_keys
835+ unique_ptr[CColumnDecryptionPropertiesBuilder] column_builder
836+ c_string c_column_path
837+ c_string c_column_key_str
838+ CSecureString c_column_key
817839
818840 if not isinstance (footer_key, bytes):
819841 raise TypeError (
@@ -828,6 +850,18 @@ def create_decryption_properties(
828850 c_footer_key = CSecureString(move(c_footer_key_str))
829851 builder.footer_key(c_footer_key)
830852
853+ if column_keys is not None :
854+ _validate_column_keys(column_keys)
855+ for column_path, key in column_keys.items():
856+ c_column_path = tobytes(column_path)
857+ c_column_key_str = < c_string> key
858+ c_column_key = CSecureString(move(c_column_key_str))
859+ column_builder.reset(
860+ new CColumnDecryptionPropertiesBuilder(c_column_path))
861+ column_builder.get().key(c_column_key)
862+ c_column_keys[c_column_path] = column_builder.get().build()
863+ builder.column_keys(c_column_keys)
864+
831865 if aad_prefix is not None :
832866 if not isinstance (aad_prefix, bytes):
833867 raise TypeError (
@@ -853,6 +887,7 @@ def create_encryption_properties(
853887 bint store_aad_prefix = True ,
854888 encryption_algorithm = " AES_GCM_V1" ,
855889 bint plaintext_footer = False ,
890+ column_keys = None ,
856891):
857892 """
858893 Create FileEncryptionProperties using a direct footer key.
@@ -871,18 +906,12 @@ def create_encryption_properties(
871906 prefer it unless you have a specific reason to manage
872907 keys yourself.
873908
874- .. note::
875- Currently only uniform encryption (single key for footer and all
876- columns) is supported with this method. Per-column keys are not
877- yet available; the provided key encrypts both the footer and
878- every column.
879-
880909 Parameters
881910 ----------
882911 footer_key : bytes
883- The encryption key for the file footer and all columns (uniform
884- encryption). Must be 16, 24, or 32 bytes for AES-128, AES-192,
885- or AES-256 respectively.
912+ The encryption key for the file footer. Also encrypts every column
913+ when ``column_keys`` is not specified (uniform encryption). Must be
914+ 16, 24, or 32 bytes for AES-128, AES-192, or AES-256 respectively.
886915 aad_prefix : bytes, optional
887916 Additional Authenticated Data prefix for cryptographic binding.
888917 store_aad_prefix : bool, default True
@@ -896,6 +925,12 @@ def create_encryption_properties(
896925 plaintext_footer : bool, default False
897926 Whether to leave the file footer unencrypted. When True, file
898927 schema and metadata are readable without a key.
928+ column_keys : dict[str, bytes], optional
929+ Keys for columns to encrypt, mapped by their full Parquet column
930+ paths (dot-separated for nested fields). Keys must be 16, 24, or
931+ 32 bytes. When specified, columns not in this dictionary remain
932+ unencrypted. If omitted, all columns use ``footer_key``.
933+ An empty dictionary is not allowed.
899934
900935 Returns
901936 -------
@@ -922,6 +957,10 @@ def create_encryption_properties(
922957 CFileEncryptionPropertiesBuilder* builder
923958 shared_ptr[CFileEncryptionProperties] props
924959 ParquetCipher cipher
960+ c_map[c_string, shared_ptr[CColumnEncryptionProperties]] c_column_keys
961+ c_string c_column_path
962+ c_string c_column_key_str
963+ CSecureString c_column_key
925964
926965 if not isinstance (footer_key, bytes):
927966 raise TypeError (
@@ -939,6 +978,16 @@ def create_encryption_properties(
939978 try :
940979 builder.algorithm(cipher)
941980
981+ if column_keys is not None :
982+ _validate_column_keys(column_keys)
983+ for column_path, key in column_keys.items():
984+ c_column_path = tobytes(column_path)
985+ c_column_key_str = < c_string> key
986+ c_column_key = CSecureString(move(c_column_key_str))
987+ c_column_keys[c_column_path] = \
988+ CColumnEncryptionProperties.WithColumnKey(c_column_key, b" " )
989+ builder.encrypted_columns(c_column_keys)
990+
942991 if aad_prefix is not None :
943992 if not isinstance (aad_prefix, bytes):
944993 raise TypeError (
0 commit comments