Decrypt in Snowflake using Unix command - unix

I am facing an issue where I have to decrypt a db column in Snowflake.The transformation to decrypt the column is a unix command.How do I achieve this decryption in Snowflake.

If you have a row with normal data and one column that is encrypted, and
are not prepared to decrypt the column prior to loading the data into Snowflake
you are also not prepared to decrypt the column after returning result rows from Snowflake via a query.
Then point 2 would imply you ether cannot decrypt client side, OR you need the results to do some form of JOIN/Filtering on, that it would make sense to store the data non-encrypted.
When you refer to decrypt as a command line tool, implies to you are ether encrypting the whole file/pipe-stream with does not match your column reference.
But if you have to decrypt in Snowflake you will need to implement a Javascript UDF to do that. You might find the Using Binary Data doc's helpful.

You can't run unix commands in the Snowflake environment.
If you can't do client side decryption on the way in or out, you have to figure out what the unix command actually does and hopefully you will be able to recreate it using the Cryptographic/Checksum functions.

Related

Consuming Client-Side Encrypted Data from Snowflake

I am trying to ingest client side encrypted data files from S3 to Snowflake, and want to query the data in Snowflake in readable format using Snowflake SQLs.
I have encrypted the data file using AES 256 and placed in S3. Also, followed the pre requisites of setting up my external stage with MASTER_KEY (AES-256, base64 encoded). However when I read data, it does not show me in readable format.
I would like to know if client side encrypted data can be read in the clear in Snowflake with the right authentication and authorization (without having to unload them back to S3).
Thanks in advance.

Redshift Column Level Encryption and Decryption

I want to load data (few encrypted fields) into Redshift and few users should have access to decrypt those encrypted fields. Please suggest the best approach to achieve the result.
I tried the below python udf but it did not work.
Redshift Python encrypt/decrypt UDF Error - String contains invalid or unsupported UTF8 codepoints
How should we enable to encryption/decryption at column/field level in Redshift
If you wish to secure the data by encrypting the data, you would need a way to pass the encryption key with the query, otherwise anybody with permissions to use the UDF could decrypt the data by simply calling the Decrypt UDF. Such encryption is only useful if you wish to enforce encryption at rest, which is easier done by configuring Redshift to encrypt all data at rest. (Note that this can have a performance impact.)
The recommended method of controlling access to columns is to restrict access to the underlying table, but grant access to a VIEW that contains only the permitted columns:
CREATE VIEW my_view AS SELECT col1, col3 from my_table;
GRANT SELECT ON my_view TO GROUP restricted_group;
REVOKE ALL ON my_table FROM GROUP restricted_group;

Transferring encrypted data using Sqoop

Is this use case possible:
To first extract data, encrypt it, transfer it over the network, decrypt it and load in hive or HDFS using Sqoop?
You can achieve this by following below steps :
Use sqoop codegen tool to generate mapper code which handles deserialization of table data.
Modify this code to encrypt the data read from table. Each instance represents one row.
Now run sqoop import command which will use this modified mapper code to generate encrypted data. This is transmitted to hdfs.
Use decryption logic over output files in hdfs to get back the content.

Verifying MariaDB 10.1 encryption

I have set up table-level InnoDB database encryption on MariaDB.
I'd like to know if there is any way to confirm that the data is truly encrypted. I've tried searching /var/lib/mysql/ibdata1 for sample data in the tables, but I don't know if that's a reliable test or not.
I posted this question on mariadb.com, and the suggestion there was to perfom a grep for some known data.
A DBA at Rackspace suggested using the strings command instead, to better handle the binary data, for example:
strings /var/lib/mysql/sample_table/user.ibd | grep "knownuser"
This approach returns no results on an encrypted table and does return results on an unencrypted table (assuming both have "knownuser" loaded into them).
You can query information_schema.innodb_tablespaces_encryption. When innodb tablespace is encrypted it is present in the table.
SELECT * FROM information_schema.INNODB_TABLESPACES_ENCRYPTION
WHERE NAME LIKE 'db_encrypt%';
source
My advice for testing is to copy the full dataset to another node without the encryption keys in place and try to start MySQL and query the encrypted tables. I'm making an (big) assumption that they will not be readable since the valid encryption keys are missing.
To parse the files on disk as they lay may prove difficult unless you have a special tool to do this. Maybe something like Jeremy Cole's innodb_ruby would be another litmus test https://github.com/jeremycole/innodb_ruby.
[probably don't works if you change the key which encrypts the log.]
Stop the database server.
BACKUP the keyfile
Change a key in the keyfile. (don't delte - it still has to remain a valid key otherwiese the server can't restart)
Start MariaDB again.
Try to read the table (e.g. with phpMyAdmin).
If encrypted correctly there is an answer: "The table is encrypted..." when trying to read the encryted table.
Stop Maria
Restore the backup
Restart Maria

Decrypting an encrypted text file generated using PL/SQL, encryption type AES256/CBC/PKCS5

I generated a text file, obtaining data from columns in a table. I have then encrypted that data using PL/SQL and encryption type of AES256/CBC/PKCS5.
I now need a program for the end user to use to decrypt that text file without needing to have oracle installed. (I know the solution of how to do it in Oracle, but the end user would not have Oracle installed)
So if you know of a good program, please post.
Ryan
Export to an accessible format before you encrypt.

Resources