Skip to content

Instantly share code, notes, and snippets.

@mujahidk
Created December 22, 2017 23:40
Show Gist options
  • Save mujahidk/7fdda0c69d11fc3e4a0907ce4ea77537 to your computer and use it in GitHub Desktop.
Save mujahidk/7fdda0c69d11fc3e4a0907ce4ea77537 to your computer and use it in GitHub Desktop.
Base64 encoding and decoding in Groovy.
def text = "Going to convert this to Base64 encoding!"
// Encode
def encoded = text.bytes.encodeBase64().toString()
println encoded
// Decode
byte[] decoded = encoded.decodeBase64()
println new String(decoded)
@mujahidk
Copy link
Author

mujahidk commented Oct 29, 2019 via email

@Sevastyan
Copy link

Got it working. Thanks.

def binaryFile = file("pathToBinaryFile")
        file("pathToBase64EncodedContent").withInputStream { input ->
            binaryFile.withOutputStream { output ->
                output.write(Base64.decoder.decode(input.text))
            }
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment