如何在python中解密密码

如何在python中解密密码,python,python-3.x,password-protection,password-encryption,jceks,Python,Python 3.x,Password Protection,Password Encryption,Jceks,我的代码正在使用pyspark连接到sql server。对于该连接,我将获得jceks中的加密密码。如何解密该密码并使用从sql server加载表。请建议 import pyspark import re from pyspark_llap import HiveWarehouseSession from pyspark.sql.functions import struct from pyspark.sql.functions import * from pyspark.sql.sessi

我的代码正在使用pyspark连接到sql server。对于该连接,我将获得jceks中的加密密码。如何解密该密码并使用从sql server加载表。请建议

import pyspark
import re
from pyspark_llap import HiveWarehouseSession
from pyspark.sql.functions import struct
from pyspark.sql.functions import *
from pyspark.sql.session import SparkSession

spark = SparkSession \
    .builder \
    .appName("Python Spark SQL data source example") \
    .getOrCreate()

hive = HiveWarehouseSession.session(spark).build()

df1 = spark.read.format("jdbc") \
    .option("url", "URL") \
    .option("driver", "com.microsoft.sqlserver.jdbc.SQLServerDriver") \
    .option("dbtable", "tableName") \
    .option("user", "user") \
    .option("password", "password_alias").load()

我知道现在回答这个问题有点晚了,这是将别名作为密码传递的方法之一

您需要使用hadoopConfiguration解密密码\u别名,并将其传递给spark

#Declaring Jceks path and password alias path
    jceks_path="jceks://hdfs/sqlserver.password.jceks"
    alias="password_alias"

# Reading the path of jceks using hadoopConfiguration
    conf = spark.sparkContext._jsc.hadoopConfiguration()
    conf.set('{0}'.format("hadoop.security.credential.provider.path"), jceks_path)

# Get password and make it a string.
    credential_raw = conf.getPassword(alias)
    password = ''
        for i in range(credential_raw.__len__()):
            password = password + str(credential_raw.__getitem__(i))

# Pass the password string to spark.
    df1 = spark.read.format("jdbc") \
        .option("url", "URL") \
        .option("driver", "com.microsoft.sqlserver.jdbc.SQLServerDriver") \
        .option("dbtable", "tableName") \
        .option("user", "user") \
        .option("password", password).load()

@AmruthaK听起来像是
jceks
是Java专有的,所以您需要使用它来与libs交互;此对话已结束。请使用pyjks python模块解密。我从这个链接得到了问题的答案。