Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.
Originally posted by: awilliams1024Hi Zeeshan,
If the data that has been encoded is textual in nature the following may provide you with a solution (copy and paste the code below into the BRE canvas):
node:Base64_Decoder_5
bretype:core::Filter
editor:Label=Base64 Decoder
editor:sortkey=574d47a940d63e39_5
input:@40fd2c74167f1ca2/=
output:@40fd2c7420761db6/=
prop:Script=<<EOX
if firstExec then {
base64Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
}
## Get the base64 string to be converted
x_ = {{^Field^}}
## Remove any line breaks
x_ = x_.replace("\r","").replace("\n","")
## Get the length of the string
len_x = strlen(x_)
## Verify the string length is a multiple of 4 characters
if mod(len_x, 4) != 0 then abort("Invalid base64 string (incorrect length).\n")
## If the input string is NULL return a NULL string
if(isNull(x_)) then {
returnStr = str(null)
}
## If the input string is empty return an empty string
else if(len_x == 0) then {
returnStr = ""
}
else {
## Get the number of padding characters in the base64 string
padStr = ""
numEquals = 0
if(substr(x_, len_x - 2, 1) == "=") then {
padStr = "AA"
}
else if(substr(x_, len_x - 1, 1) == "=") then {
padStr = "A"
}
returnStr = ""
## Replace the padding characters with "A" characters
x_ = substr(x_, 0, len_x - strlen(padStr)) + padStr
## Increment over the base64 string 4 characters at a time
i = 0
while i < len_x {
## Get the four characters to be converted in this iteration
firstChar = substr(x_, i, 1)
secondChar = substr(x_, i+1, 1)
thirdChar = substr(x_, i+2, 1)
fourthChar = substr(x_, i+3, 1)
## Each of these four characters represents a 6-bit index in the
## base64 characters list which, when concatenated, will give the
## 24-bit number for the original 3 characters
idx = bitwiseLeftShift(strFind(base64Chars, firstChar), 18)
idx = idx + bitwiseLeftShift(strFind(base64Chars, secondChar), 12)
idx = idx + bitwiseLeftShift(strFind(base64Chars, thirdChar), 6)
idx = idx + strFind(base64Chars, fourthChar)
## Add the converted characters to the return string
returnStr = returnStr
+ chr(bitwiseAnd(bitwiseRightShift(idx, 16), 255))
+ chr(bitwiseAnd(bitwiseRightShift(idx, 8), 255))
+ chr(bitwiseAnd(idx, 255))
i = i + 4
}
}
emit returnStr as "decoded_Data",*
exclude {{^Field^}}
EOX
editor:XY=490,160
editor:UsageDoc=Decodes a Base64 encoded string field.
editor:Doc=Decodes a Base64 encoded string field.
editor:propdef=Field|string|Input||Not Blank
editor:propdoc=Field=The field containing the base64 encoded data.
end:Base64_Decoder_5
Regards,
Adrian