Search code examples
groovybase64soapuidecodebinary-data

Base64 decode a binary content with Groovy script


I use following script to decode a Base64 coded binary content and put it into a string then write to file.

byte[] decoded = slurper.signatureValue.decodeBase64();
String sigValue = new String(decoded)

def path = context.expand('${Properties#outDir}') + context.expand('${Properties#fileName}')
def myFile = new File(path)
myFile.write(sigValue)

When I use Notepad++ with MIME tools plugin to decode it and save it, output is different and not sure, what is difference caused by.


Solution

  • The following code produces valid(same as Notepad++ plugin) value:

    byte[] decoded = Base64.getDecoder().decode(slurper.signatureValue);
    myFile.bytes = decoded