scalaencryptionapache-spark-sqlsalt-cryptographysha2

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


Solution

  • Try this:

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