Hello All,
Below is the code snippet from Ruby.
Digest::SHA256.base64digest('')
I need to generate the same in Appian and pass it to the integration header parameter, please let me know if anyone has done this before.
Thank You,
Sneha.
Discussion posts and replies are publicly visible
Can you clarify on what you mean exactly by "base64 digest string"? What is your input and what is your desired output? If, for example, it just requires translation of a string to Base64, this can be done OOtB.
Hello Mike,
Thank You for the response.
I need to get the equivalent hash value of the given string. First, need to get the SHA256 hash of the given string and convert the value to base64.
I've done using Java code and exposed it as an Appian function.
That sounds good. I've previously written an OOB Appian expression to convert text to Base64, but I don't have any solution for the SHA256 hash portion so i'm glad you figured something out. Did you develop this as a plug-in or use some other method to expose it to Appian, if I may ask?
Yes, I developed it as an Appian plug-in.
May I know the Appian OOB expression which converts text to Base64?
I just wrote one myself a year or so ago. Let me see if I can find where I saved the rule code...edit: here you go--
/* encode */ a!localVariables( /*local!text: "Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.",*/ local!text: ri!text, local!charset: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", local!codeArray: code(local!text), local!bins: concat(dec2bin(local!codeArray, 8)), local!groupedBins: split(concat( a!forEach( code(local!bins), char(fv!item) & if(and(mod(fv!index, 6) = 0, not(fv!isLast)), "-=-=-", "") ) ), "-=-=-" ), local!lastBin: index(local!groupedBins, length(local!groupedBins)), local!padding: if( len(local!lastbin) = 2, "==", len(local!lastbin) = 4, "=", len(local!lastbin) = 6, "", "error condition" ), local!bindexes: a!forEach( local!groupedBins, if( fv!isLast, bin2dec(substitute(padright(fv!item, 6), " ", "0")), bin2dec(fv!item) ) ) + 1, local!assembledOutput: concat(a!forEach(local!bindexes, charat(local!charset, fv!item))) & local!padding, local!assembledOutput )
Hi Mike,This code snippet, will help us to convert simple text to base64 ?
Neha Dangi said:This code snippet, will help us to convert simple text to base64 ?
Yes, the code I posted (which is custom code I wrote 100% from scratch on my own in Appian) should generate standard Base64 given an input string. I've tested the base64 it generates with external base64 convertors and at least thus far I haven't found any areas where it doesn't work correctly.
Mike, do you happen to have a base64 decoder written as well? I'll try to reverse engineer your encoder in the meantime. Thanks!
Jason said:do you happen to have a base64 decoder written as well?
In fact, yes.
/* decode */ a!localVariables( local!base64text: ri!base64text, local!charset: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", local!charCodes: code(local!base64text), /*local!paddingCount: count(wherecontains(code("="), local!charCodes)),*/ local!unpaddedChars: a!flatten(a!forEach( items: local!charCodes, expression: if(fv!item = code("="), {}, find(char(fv!item), local!charset)-1) )), local!rawBins: dec2bin(tointeger(local!unpaddedChars), 6), local!decodedBins: split( concat( a!forEach( items: code(concat(local!rawBins)), expression: if( mod(fv!index, 8) = 0, char(fv!item) & "-=-=-", char(fv!item) ) ) ), "-=-=-" ), concat( a!forEach( items: local!decodedBins, expression: if( or(fv!item = "0000", fv!item = "00"), null(), char(bin2dec(fv!item)) ) ) ) )
You sir, are my hero!
Great work!!!
Have you tested the limits of characters for this code?
Alexis Díaz Fajardo said:limits of characters
Within reason. Do you have anything specific in mind?
To confirm - i just tested it on a 10,000 character randomly-generated Lorem Ipsum text, and it worked in less than 5 seconds. I guess I'd hesitate to call it on text much longer than this, just for performance concerns.
Thats nice to hear. Im asking because the plugin Base64 Expressions have in its functions a character limit of 150.
Alexis Díaz Fajardo said:character limit of 150
yikes
edit: have you tested this: a few comments there suggest the limit is actually more than 150 characters now (in spite of what they have published on the description page). I updated my version of the plug-in and it seems to take upwards of 1600 characters now (the old one did break at 152, instead of 150 oddly).