# Grail Base64 编码和解码

**URL:** <https://www.isharkfly.com/t/grail-base64/7073>\
**Category:** 程序语言\
**Created:** [September 12, 2014, 7:21pm UTC](https://www.isharkfly.com/t/grail-base64/7073 "2014-09-12T19:21:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![honeymoose](https://www.isharkfly.com/user_avatar/www.isharkfly.com/honeymoose/32/20796_2.png) [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Post date:** [September 12, 2014, 7:21pm UTC](https://www.isharkfly.com/t/grail-base64/7073/1 "2014-09-12T19:21:12Z")

</div>

请参考下面的代码。

Grails Base 64 的编码和解码。[code]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[/code]
