chovy-3012 opened a new issue, #13377: URL: https://github.com/apache/seatunnel/issues/13377
### Search before asking - [x] I had searched in the [feature](https://github.com/apache/seatunnel/issues?q=is%3Aissue+label%3A%22Feature%22) issues and found no similar feature requirement. ### Description SM4 is the Chinese national standard 128-bit block cipher (GB/T 32907-2016, part of the "GM" commercial-cryptography suite). Security-compliance requirements in regulated sectors in China (finance, government, telecom) increasingly mandate SM4 rather than AES for encrypting sensitive fields at rest, and several databases commonly used with SeaTunnel (Doris, OceanBase, openGauss and other GM-compliant databases) already provide SM4 in their SQL function sets. The SQL transform currently offers `AES_ENCRYPT` / `AES_DECRYPT` and `MD5`, but no function from the SM cipher family. A job that must deliver SM4 ciphertext to a GM-compliant sink cannot encrypt inside the sync pipeline at all today: `AES_ENCRYPT` does not satisfy an SM4 mandate, so users have to run a separate post-processing step or push the encryption into the source database. Proposed functions, following the existing `AES_ENCRYPT` / `AES_DECRYPT` conventions (same argument shape, Base64 string output): ```sql SM4_ENCRYPT(value, key[, iv]) -> STRING SM4_DECRYPT(value, key[, iv]) -> STRING ``` Expected behavior, mirroring `AES_ENCRYPT` so the two cipher families stay consistent: - SM4 is a 128-bit cipher: a `base64:` key must decode to 16 bytes; any other key is treated as a passphrase and derived with SHA-256 (first 16 bytes), as in `AES_ENCRYPT` - When `iv` is omitted, a random 16-byte IV is generated per call and prepended to the ciphertext (the same Base64(IV || ciphertext) layout as `AES_ENCRYPT`), so `SM4_DECRYPT(SM4_ENCRYPT(v, k), k)` round-trips without an explicit IV - NULL input returns NULL - A wrong key or corrupted ciphertext fails with the same error handling as `AES_ENCRYPT` Reference usage — Doris, the closest ecosystem precedent (it has provided these functions since 2022, defaulting to `SM4_128_ECB`, with optional CBC / CFB128 / OFB / CTR modes): ```sql SELECT TO_BASE64(SM4_ENCRYPT('text', 'F3229A0B371ED2D9441B830D21A390C3')); SELECT SM4_DECRYPT(FROM_BASE64('aDjwRflBrDjhBZIOFNw3Tg=='), 'F3229A0B371ED2D9441B830D21A390C3'); ``` Keeping the same function names and argument shape as Doris makes it easier for users to move SM4-encrypted data between SeaTunnel and Doris, while the output format stays consistent with SeaTunnel's own `AES_ENCRYPT` conventions. No compute-engine SQL function set (Flink SQL, Spark SQL, Trino) currently provides SM4, so the database side is the only precedent to follow. ### Usage Scenario A compliance-driven ETL job: a bank must store customer PII (phone number, ID number) SM4-encrypted per its security-review standard, and the data is synced daily from a business MySQL into Doris: ```hocon transform { Sql { source_table_name = "customers" result_table_name = "customers_encrypted" query = "SELECT id, SM4_ENCRYPT(phone, 'base64:MTIzNDU2Nzg5MDEyMzQ1Ng==') AS phone_enc, SM4_ENCRYPT(id_no, 'base64:MTIzNDU2Nzg5MDEyMzQ1Ng==') AS id_no_enc FROM customers" } } ``` Typical patterns: - Encrypt-on-sync: PII columns are encrypted with SM4 while flowing from the source to a GM-compliant target; plaintext never lands on the target - Decrypt-on-sync: reading SM4-encrypted columns from a GM-compliant source and delivering plaintext to an internal system that is allowed to see it - Key rotation: re-run the job with a new key and the target is re-encrypted in one pass Today the only options are a separate post-processing job outside SeaTunnel or source-side encryption, both of which break the single-pipeline story. ### Related issues None. (The SQL transform already provides `AES_ENCRYPT` / `AES_DECRYPT` and `MD5`; this asks for the SM4 family.) ### Are you willing to submit a PR? - [x] Yes I am willing to submit a PR! ### Code of Conduct - [x] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
