Github user cloud-fan commented on a diff in the pull request: https://github.com/apache/spark/pull/10527#discussion_r51685577 --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/misc.scala --- @@ -453,3 +455,119 @@ case class Murmur3Hash(children: Seq[Expression], seed: Int) extends Expression } } } + +/** + * A function that encrypts input using AES. Key lengths of 128, 192 or 256 bits can be used. + * 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength + * Jurisdiction Policy Files are installed. If either argument is NULL or the key length is + * not one of the permitted values, the return value is NULL. + */ +@ExpressionDescription( + usage = "_FUNC_(input, key) - Encrypts input using AES.", + extended = "> SELECT Base64(_FUNC_('ABC', '1234567890123456'));\n 'y6Ss+zCYObpCbgfWfyNWTw=='") +case class AesEncrypt(left: Expression, right: Expression) + extends BinaryExpression with ImplicitCastInputTypes { + + override def dataType: DataType = BinaryType + override def nullable: Boolean = true + + override def inputTypes: Seq[DataType] = Seq(BinaryType, BinaryType) + + protected override def nullSafeEval(input1: Any, input2: Any): Any = { + val cipher = Cipher.getInstance("AES") + val secretKey: SecretKeySpec = input2.asInstanceOf[Array[Byte]].length match { + case 16 | 24 | 32 => + new SecretKeySpec(input2.asInstanceOf[Array[Byte]], 0, + input2.asInstanceOf[Array[Byte]].length, "AES") + case _ => null + } + + try { + cipher.init(Cipher.ENCRYPT_MODE, secretKey) + cipher.doFinal(input1.asInstanceOf[Array[Byte]], 0, input1.asInstanceOf[Array[Byte]].length) + } catch { + case e: GeneralSecurityException => null --- End diff -- yea, you followed `Sha2`, but `Sha2` may also be wrong. In this case we think rethrow exception makes more sense, and we can also fix `Sha2` later.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org