Here is a full example (first the encoding you should do once time for all, then the decoding for the user) :
Code:
def path = System.getProperty("user.dir")+"/images"
def baseFile = new File(path + "/mensclothes.png")
def encodedFile = new File(path + "/mensclothes_encoded.png")
def encodedBytes = baseFile.getBytes()
encodedBytes.eachWithIndex( { b,n -> encodedBytes[n] = (byte)(b ^ 128) } )
encodedFile.delete() //emptying
encodedFile.append(encodedBytes)
// setImage("mensclothes_encoded.png") //would fail, of course : it's encoded !
def decodedFile = new File(path + "/mensclothes_decoded.png")
def decodedBytes = encodedFile.getBytes()
decodedBytes.eachWithIndex( { b,n -> decodedBytes[n] = (byte)(b ^ 128) } )
decodedFile.delete()
decodedFile.append(decodedBytes)
setImage("mensclothes_decoded.png") //success !
The "encryption" is here a simple "xor" : the
b^128 part
Probably this code could be better, I'm no groovy wizard.