Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 80543200CBB for ; Tue, 4 Jul 2017 16:38:07 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 7ED68161556; Tue, 4 Jul 2017 14:38:07 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 9ED80161554 for ; Tue, 4 Jul 2017 16:38:06 +0200 (CEST) Received: (qmail 60449 invoked by uid 500); 4 Jul 2017 14:38:05 -0000 Mailing-List: contact issues-help@drill.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@drill.apache.org Delivered-To: mailing list issues@drill.apache.org Received: (qmail 60440 invoked by uid 99); 4 Jul 2017 14:38:05 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 04 Jul 2017 14:38:05 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 684641AFE03 for ; Tue, 4 Jul 2017 14:38:05 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -99.202 X-Spam-Level: X-Spam-Status: No, score=-99.202 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id mGj_M9ZTL-AD for ; Tue, 4 Jul 2017 14:38:03 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id 46668610D3 for ; Tue, 4 Jul 2017 14:38:02 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 9E4C2E0059 for ; Tue, 4 Jul 2017 14:38:01 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 8A95C24619 for ; Tue, 4 Jul 2017 14:38:00 +0000 (UTC) Date: Tue, 4 Jul 2017 14:38:00 +0000 (UTC) From: "ASF GitHub Bot (JIRA)" To: issues@drill.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (DRILL-5634) Add Crypto and Hash Functions MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Tue, 04 Jul 2017 14:38:07 -0000 [ https://issues.apache.org/jira/browse/DRILL-5634?page=3Dcom.atlassian= .jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=3D1607= 3753#comment-16073753 ]=20 ASF GitHub Bot commented on DRILL-5634: --------------------------------------- Github user cgivre commented on a diff in the pull request: https://github.com/apache/drill/pull/865#discussion_r125487364 =20 --- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/im= pl/CryptoFunctions.java --- @@ -0,0 +1,345 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or imp= lied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.drill.exec.expr.fn.impl; + +import io.netty.buffer.DrillBuf; +import org.apache.drill.exec.expr.DrillSimpleFunc; +import org.apache.drill.exec.expr.annotations.FunctionTemplate; +import org.apache.drill.exec.expr.annotations.Output; +import org.apache.drill.exec.expr.annotations.Param; +import org.apache.drill.exec.expr.annotations.Workspace; +import org.apache.drill.exec.expr.holders.VarCharHolder; + +import javax.crypto.Cipher; +import javax.crypto.spec.SecretKeySpec; +import javax.inject.Inject; + +public class CryptoFunctions { + static final org.slf4j.Logger logger =3D org.slf4j.LoggerFactory.get= Logger(CryptoFunctions.class); + + private CryptoFunctions() { + } + + @FunctionTemplate(name =3D "md5", scope =3D FunctionTemplate.Functio= nScope.SIMPLE, nulls =3D FunctionTemplate.NullHandling.NULL_IF_NULL) + public static class MD5Function implements DrillSimpleFunc { + + @Param + VarCharHolder rawInput; + + @Output + VarCharHolder out; + + @Inject + DrillBuf buffer; + + @Workspace + java.security.MessageDigest md; + + @Override + public void setup() { + try { + md =3D java.security.MessageDigest.getInstance("MD5"); + } catch (Exception e) { + logger.debug(e.getMessage()); + } + } + + @Override + public void eval() { + + String input =3D org.apache.drill.exec.expr.fn.impl.StringFuncti= onHelpers.toStringFromUTF8(rawInput.start, rawInput.end, rawInput.buffer); + byte[] thedigest =3D null; --- End diff -- =20 Fixed in latest version.=20 > Add Crypto and Hash Functions > ----------------------------- > > Key: DRILL-5634 > URL: https://issues.apache.org/jira/browse/DRILL-5634 > Project: Apache Drill > Issue Type: New Feature > Components: Functions - Drill > Affects Versions: 1.10.0 > Reporter: Charles Givre > Labels: doc-impacting > Fix For: 1.11.0 > > > This library contains a collection of cryptography-related functions for = Apache Drill. It generally mirrors the crypto functions in MySQL. The pack= age includes: > * **`aes_encrypt()`/ `aes_decrypt()`**: implement encryption and decrypti= on of data using the official AES (Advanced Encryption Standard) algorithm,= previously known as =E2=80=9CRijndael.=E2=80=9D > `AES_ENCRYPT()` encrypts the string `str` using the key string `key_str`= and returns a binary string containing the encrypted output. `AES_DECRYPT(= )` decrypts the encrypted string `crypt_str` using the key string `key_str`= and returns the original cleartext string. If either function argument is = NULL, the function returns NULL. > ```sql > > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS aes FROM (VA= LUES(1)); > +---------------------------+ > | aes | > +---------------------------+ > | JkcBUNAn8ByKWCcVmNrKMA=3D=3D | > +---------------------------+ > > SELECT aes_encrypt( 'encrypted_text', 'my_secret_key' ) AS encrypted, > aes_decrypt(aes_encrypt( 'encrypted_text', 'my_secret_key' ),'my_secret_= key') AS decrypted=20 > FROM (VALUES(1)); > +---------------------------+-----------------+ > | encrypted | decrypted | > +---------------------------+-----------------+ > | JkcBUNAn8ByKWCcVmNrKMA=3D=3D | encrypted_text | > +---------------------------+-----------------+ > ``` > * **`md5()`**: Returns the md5 hash of the text. (https://en.wikip= edia.org/wiki/MD5) > Usage: > ```sql > > select md5( 'testing' ) from (VALUES(1)); > +-----------------------------------+ > | EXPR$0 | > +-----------------------------------+ > | ae2b1fca515949e5d54fb22b8ed95575 | > +-----------------------------------+ > ``` > * **`sha(`) / `sha1()`**: Calculates an SHA-1 160-bit checksu= m for the string, as described in RFC 3174 (Secure Hash Algorithm). (https:= //en.wikipedia.org/wiki/SHA-1) The value is returned as a string of 40 hex= adecimal digits, or NULL if the argument was NULL. Note that `sha()` and `s= ha1()` are aliases for the same function.=20 > ```sql > > select sha1( 'testing' ) from (VALUES(1)); > +-------------------------------------------+ > | EXPR$0 | > +-------------------------------------------+ > | dc724af18fbdd4e59189f5fe768a5f8311527050 | > +-------------------------------------------+ > ``` > * **`sha2(`) / `sha256()`**: Calculates an SHA-2 256-bit chec= ksum for the string. (https://en.wikipedia.org/wiki/SHA-2) The value is re= turned as a string of hexadecimal digits, or NULL if the argument was NULL.= Note that `sha2()` and `sha256()` are aliases for the same function.=20 > ```sql > > select sha2( 'testing' ) from (VALUES(1)); > +-------------------------------------------------------------------+ > | EXPR$0 | > +-------------------------------------------------------------------+ > | cf80cd8aed482d5d1527d7dc72fceff84e6326592848447d2dc0b0e87dfc9a90 | > +-------------------------------------------------------------------+ > ``` > Additionally, there are also `sha384()` and `sha512()` functi= ons which return SHA-2 hashes with 384 and 512 bit checksums. -- This message was sent by Atlassian JIRA (v6.4.14#64029)