How to encode and decode Base64 in Grails, Groovy or Java

Posted: Fri, Mar 25 11:54 AM (PDT)

I don't know why, but function decodeBase64 in Grails doesn't work correctly. And I found other solution. See below

Now we include the base64 library

import org.apache.commons.codec.binary.Base64

Our encode function

def encodeBase64(String text) {
	return new String(Base64.encodeBase64(text.getBytes()))
}

Our decode function

def decodeBase64(String text) {
	return new String(Base64.decodeBase64(text))
}

That's all

Tags: