数据在MYSQL中以
'
“´¾´^-|"ªêãæ'
”的格式进行加密。
MYSQL 列定义是
Column: mobile
Collation: latin1_swedish_ci
Definition: varchar(16)
在MYSQL中解密我使用
CONVERT(AES_DECRYPT(mobile, my_KEY) using utf8 ) as mobile
与 pySPARk SQL 相同,胶水作业不起作用。
我试过了,
CAST(AES_DECRYPT(mobile, my_KEY, "ECB", "PKCS") AS STRING) AS mobile
并出现错误提示 The value of parameter(s) 'expr, key' in the
aes_encrypt/
aes_decryptfunction is invalid: Detail message: Input length must be multiple of 16 when decrypting with padded cipher
出现
也尝试了其他模式,但都导致了一些错误。 还尝试了
unhex(mobile)
,结果为 NULL。
任何帮助将不胜感激。谢谢。
我花了几个小时试图让它发挥作用,但没有成功。我确实找到了一种解决方法,即将列解密作为对 MySQL 数据库的原始查询的一部分。整个文件链接如下,但解决方法如下:
query = "select id, testcol1, convert(aes_decrypt(testbin, '" + db_key + "') using utf8) as testbin from testtable1"
spark = SparkSession.builder.appName("test").getOrCreate()
df = spark.read \
.format("jdbc") \
.option("url", "jdbc:mysql://localhost/testdb1") \
.option("query", query) \
.option("user", db_user) \
.option("password", db_password) \
.load()
https://github.com/JacobSteelsmith/spark/blob/master/python/readmysql.py