user10360768
user10360768

Reputation: 225

How can I encrypt spark sql data frame column using SHA-2 and a random salt

I am working in Scala programming language. I want to encrypt entire column of spark sql data frame using SHA-2 algorithm and a random salt

what I have so far is this and it works well

dataFrame.withColumn("ColumnName", sha2(bin(col("ColumnName")), 256))

How can I add salt to this hashing?

Thanks

Upvotes: 0

Views: 2806

Answers (1)

NNZ
NNZ

Reputation: 51

Try this:

df.withColumn("ColumnName", 
              sha2(concat_ws("|", lit("left_salt"), bin(col("yourcoltocrypt")), lit("right_salt"))), 256))

Upvotes: 1

Related Questions