Nintex Workflow – Adding Custom Inline Functions (Encryption)
Posted on 02 August 2010 by Jason Grimme
Recently I have been experimenting with Nintex Workflows which I must say is a killer product. The interface is brilliant and the depth of its features is amazing. One of the great features of Nintex Workflows is that it allows you to use common .NET calls as inline functions.
One would think that Nintex made an easy way to create your own, but sadly they missed that feature. While they didn’t make it easy, they did make it possible
Let’s say we want to add some encryption functions into our workflow. For what reason? I don’t know. But it seemed like a good example. I decided for you that you want to generate MD5 and SHA1 hashes in addition to the wimpy base-64 encode. You will need decently high privileges in order to add your function, as you will need access to stsadmn.exe, NWAdmin.exe, in addition to some knowledge of .NET.
Create your class
To start things off, create a new Class Library. Next create a class within a namespace, and make your methods static:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | namespace NWEncryptionMethods { class EncryptionMethods { // Create md5 hash static public string GetMD5Hash(string s) { System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider(); byte[] data = System.Text.Encoding.ASCII.GetBytes(s); data = x.ComputeHash(data); string encStr = ""; for (int i = 0; i < data.Length; i++) encStr += data[i].ToString("x2").ToLower(); return encStr; } // Create SHA1 hash static public string GetSha1Hash(string s) { System.Security.Cryptography.SHA1 sha1 = System.Security.Cryptography.SHA1CryptoServiceProvider.Create(); byte[] encodeBytes = Encoding.ASCII.GetBytes(s); byte[] encodeHashedBytes = sha1.ComputeHash(encodeBytes); return BitConverter.ToString(sha1.ComputeHash(encodeBytes)).Replace("-", "").ToLowerInvariant(); } // Create base-64 encoded string static public string GetBase64Encode(string s) { byte[] encodedBytes = System.Text.Encoding.UTF8.GetBytes(s); return Convert.ToBase64String(encodedBytes); } } } |
Next up you will need to make this into a deployable solution. Make sure it is strongly named and signed so that it is ready to go into the GAC.
Deploying to SharePoint
1 2 3 | stsadm.exe -o AddSolution -filename NWEncryptionMethods.wsp stsadm.exe -o DeploySolution -name NWEncryptionMethods.wsp -immediate -allowgacdeployment stsadm.exe -o execadmsvcjobs |
Adding to Nintex Workflow vi NWAdmin
1 2 3 | NWAdmin.exe -o AddInlineFunction -functionalias fn-NWGetMD5Hash -assembly "NWEncryptionMethods, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxx" -namespace NWEncryptionMethods -typename EncryptionMethods -method GetMD5Hash NWAdmin.exe -o AddInlineFunction -functionalias fn-NWGetSha1Hash -assembly "NWEncryptionMethods, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxx" -namespace NWEncryptionMethods -typename EncryptionMethods -method GetSha1Hash NWAdmin.exe -o AddInlineFunction -functionalias fn-NWGetBase64Encode -assembly "NWEncryptionMethods, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxx" -namespace NWEncryptionMethods -typename EncryptionMethods -method GetBase64Encode |
Using Your Custom Function in String Builder
Alright, so your class is created, it is in SharePoint, and it has been added to Nintex. If you open up a Nintex workflow, you should now be able to use your functions with the names you gave them in the NWAdmin.exe tool.
Example Usage: fn-NWGetMD5Hash(fn-NWGetSha1Hash(fn-NWGetBase64Encode(“Jason Grimme”)))
Tags | .NET, C#, Encryption, Nintex, SharePoint
