Alteryx Designer

Find answers, ask questions, and share expertise about Alteryx Designer.

How do i SHA-256 Hash (and other hashing too)? (Solution)

Highlighted
6 - Meteoroid

How do i Hash a column from my input?

(This covers different types of hashing, a list of available hashes can be found at the end)

 

The Story 

I was looking for support on how to simply change one column from my input data to SHA-256 Encryption. i couldn't really find any support, or articles that could help, That were what i was looking for. something simple yet really helpful. i went from using the HMAC Tool (But this never set the hash to Hex, and always asks for a key), i understand there is the omnibus package, but to download this from a blog isn't always secure. so in the best interest of security. i had to work out a way around this.

 

i worked out how to do this but took me some time, so to save someone some time in the future. (with GDPR regulations and internet security increasing) 

This is how i added the cryptographic hash to my Work flow. 

 

The Task

Use the SHA256 Hashing Algorithm for Customer Detail Data.

 

Essentially, Change your data to a SHA256 hash and match the target requirement.

 

TextTarget Hash
abc@gmail.com48ddb93f0b30c475423fe177832912c5bcdce3cc72872f8051627967ef278e08
abcBA7816BF8F01CFEA414140DE5DAE2223B00361A396177A9CB410FF61F20015AD
abcdefghijklmnopqrstuvwxyz248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1

 

The Process

My Workflow:

sha256.PNG

 

 

 

 

 

 

 

 

 

 

 

 

My input is just a simple text input with the following rows


text input.PNG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Then i select the Single Column, in this case there is only one column, but when integrating this with your work flow you may have many columns.

The column you select will be the column you wish to change to SHA-256 or similar hashes, a list of available hashes will be at the bottom of this post.

 

i then select the R tool, This can be found in the Developers Ribbon. There are some sites out there that help you understand R and how it integrates,

but i have tried to keep my comments in the code for this short and sweet. N.b When i started this, i didnt have a clue how to Code in R. 

the screen shot below shows the code i used with all the comments.

 

R in Alteryx uses CRAN as its framework for Packages/Libraries.

Below you will see that i have used OpenSSL as the package. This allows you to easily encrypt data. but i wont go into detail. you can read about the package here

Open SSL

 

 

r.PNG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

You can use the below to copy into your Tool.

 

 

# R uses CRAN Packages
# A list of these can be found 
# https://cran.r-project.org/web/packages/available_packages_by_name.html

# Set R to use the OpenSSL Library
library("openssl")

# Grab the Data from Alteryx
df <- read.Alteryx("#1", mode="data.frame")

# Loop data from Alteryx, ensuring that the loop selects each row 
for (row in 1:nrow(df))
# This function uses OpenSSL to Encrypt Your text
# More information can be found here 
# https://cran.r-project.org/web/packages/openssl/index.html
# information about the package can be found here
# https://cran.r-project.org/web/packages/openssl/openssl.pdf
f<- function(x, output)
{
a <- sha256(x[1])
output <- print(a)
}

#This sets how you would like to output your data onto the tool.
# i chose dataframe, as this can be renamed easily
# but you can choose list (however this puts first record as Header)
output <- as.data.frame(apply(df,1,f,output = 'outputfile'))
#This then writes your output to the R tool on your workflow.
# setting TRUE, gives the Row a name. In this case i have used as a record ID
write.Alteryx(output,1,TRUE)

In the output you will see the results These will match the requirements.

 

I have also attached the workflow below.

 

List of Support Hash Types with OpenSSL.

ripemd160WithRSA
ssl2-md5
A224
md4
sha512
RSA-SHA256
DSA-SHA
sha1WithRSAEncryption
MD5
MD4
ssl3-sha1
ripemd160
sha
SHA384
SHA1
ssl3-md5
sha256
sha384WithRSAEncryption
SHA512
DSA-SHA1-old
dsaWithSHA1
ecdsa-with-SHA1
whirlpool
RSA-RIPEMD160
rmd160
RIPEMD160
RSA-SHA1-2
RSA-SHA1
dsaWithSHA
md5WithRSAEncryption
DSS1
RSA-MD5
dsaEncryption
ripemd
md4WithRSAEncryption
DSA
sha512WithRSAEncryption
SHA
dss1
RSA-SHA224
RSA-SHA512
SHA256
md5
RSA-SHA384
sha1
sha224WithRSAEncryption
RSA-SHA
shaWithRSAEncryption
sha256WithRSAEncryption
DSA-SHA1
RSA-MD4

 

Highlighted
Alteryx Partner

I've done the same in Python, but for SHA256 only at the moment.

6 - Meteoroid

Hi

 

it might be good to share your workflow on how you did it below, so that others can see your work? or put a link if your solution is elsewhere and link it here. enabling the community to look at many ways to use it. 

i know that some users wont know coding to the nth degree like some of us developers, so sharing is caring

Highlighted
Alteryx Partner

I'm definitely going to share it, I just want to see if I can expand the list a bit more (or at least explain how to expand the list :) )

Labels