GithubHelp home page GithubHelp logo

trino-encrypt-udfs's Introduction

trino-encrypt-udfs

Example of Trino UDFs Plugin to encrypt and decrypt values with a password.

Introduction

In Trino you can create new Plugins by implementing interfaces and override methods defined by the SPI.

Plugins can provide additional Connectors, Types, Functions and with this project we implement 2 new SQL Functions (or UDFs / User-Defined Functions) to encrypt or decrypt a value (from a column or not) with a password.

The method used to encrypt a value is PBE (Password Based Encryption), a method where the encryption key (which is binary data) is derived from a password (string). PBE is using an encryption key generated from a password, random salt and number of iterations. Details on Java implementation, we use the PBEWithMD5AndDES mode.

Build

requires

  • Java 11
  • Maven 4.0.0+ (for building)
mvn clean package

If you want skip unit tests, please run:

mvn clean package -DskipTests

It will generate a trino-encrypt-udfs-{version}.jar and trino-encrypt-udfs-{version} folder in target directory.

Deploy

Copy the trino-encrypt-udfs-{version} folder from target directory in your Trino plugin directory and restart Trino server.

% cp -R ./target/trino-encrypt-udfs-{version} <trino-server-folder>/plugin/trino-encrypt-udfs

% <trino-server-folder>/bin/launcher restart

Then you should find 2 new functions encrypt and decrypt if you list all available functions of your Trino server with SHOW FUNCTIONS SQL command:

"encrypt","varchar","varchar, varchar","scalar","true","UDF to encrypt a value with a given password"

"decrypt","varchar","varchar, varchar","scalar","true","UDF to decrypt a value with a given password"

Usage

With a local trino server and trino CLI you can test the UDFs with:

%<trino-cli-folder>/trino --execute "SELECT encrypt('myvalue','mypassword')"

SQL queries to use and test functions:

SELECT decrypt(encrypt('myvalue','mypassword'),'mypassword')

SELECT decrypt(encrypt('myvalue','mypassword'),'my_new_password')

With last query you must get the message "Wrong password for decryption".

Tests on a tpch table:

SELECT encrypt(name,'new_password') FROM tpch.sf1.region

To create a table with encrypted data:

CREATE TABLE your_catalog.your_schema.region_encrypt AS SELECT encrypt(name,'new_password') FROM tpch.sf1.region

Trino udfs queries

trino-encrypt-udfs's People

Contributors

victorcouste avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

trino-encrypt-udfs's Issues

Issue when running mvn clean package

requires
Java 11
Maven 4.0.0+ (for building)
Did all the above but this command gives error

mvn clean package

[INFO] --------------------------------------------------------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] --------------------------------------------------------------------------------------------------------------------------
[INFO] Total time: 2.405 s
[INFO] Finished at: 2023-04-19T18:09:47Z
[INFO] --------------------------------------------------------------------------------------------------------------------------
[ERROR] Failed to execute goal io.trino:trino-maven-plugin:11:check-spi-dependencies (default-check-spi-dependencies) on project trino-encrypt-udfs: Failed to resolve dependencies.: Failed to read artifact descriptor for io.trino:trino-spi:jar:364: The following artifacts could not be resolved: io.airlift:airbase:pom:112 (present, but unavailable): Could not find artifact io.airlift:airbase:pom:112 in confluent (https://packages.confluent.io/maven/) -> [Help 1]
[ERROR]

New to java

Hello can i get a step by step guide on how to create my own function , package it into a valid trino plugin and upload it?
i checked the guide on trino website but I could not follow,
Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.