Groovy web console

subscribe to the feed Subscribe
to this
site
Base64 encoding/decoding (via #groovywebconsole)
tweet this snippet Tweet
this
script

Base64 encoding/decoding

Published 10 years ago by mrhaki with tags string base64 encode decode
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
def s = 'Argh, Groovy you say, mate?'

String encoded = s.bytes.encodeBase64().toString()
assert 'QXJnaCwgR3Jvb3Z5IHlvdSBzYXksIG1hdGU/' == encoded

byte[] decoded = encoded.decodeBase64()
assert s == new String(decoded)