Base64 encoder/decoder class
Introduction
The Base64 class can encode String or ByteArray objects to Base64 encoding, and vice versa.
Note that this class is ActionScript 3.0 only as there are several good alternatives written for ActionScript 2.0. Just google them.
Download
The current version of the Base64 class is 1.0.0.
Usage
Encoding from and decoding to string:
-
import com.dynamicflash.util.Base64;
-
-
var source:String = "Hello, world";
-
var encoded:String = Base64.encode(source);
-
trace(encoded);
-
-
var decoded:String = Base64.decode(encoded);
-
trace(decoded);
Encoding from and decoding to ByteArray:
-
import com.dynamicflash.util.Base64;
-
-
var obj:Object= {name:"Dynamic Flash",url:"http://dynamicflash.com"};
-
var source:ByteArray = new ByteArray();
-
source.writeObject(obj);
-
-
var encoded:String = Base64.encodeByteArray(source);
-
trace(encoded);
-
-
var decoded:ByteArray = Base64.decodeToByteArray(encoded);
-
obj = decoded.readObject();
-
trace(obj.name + "(" + obj.url + ")");
History
- 1.0.0
- Initial release
Bug reports
Please post bug reports as comments to this page.
License
The Base64 class is released under the MIT license.
Copyright © 2006 Steve Webster
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.








[...] For more information see the Base64 class page, which
ActionScript 3.0 Base64 encoder/decoder at Dynamic Flash | Wednesday, 27 September 2006 | 8:51 pm[...] For more information see the Base64 class page, which is part of the revamped Goodies section. [...]
[...] Base64 encoder/decoder class at Dynamic Flash (tags: Base64 as3)
danielyuen.hk Blog : links for 2006-09-29 | Friday, 29 September 2006 | 12:50 am[...] Base64 encoder/decoder class at Dynamic Flash (tags: Base64 as3) [...]
Dude, you rock. This works great, and was exactly
Chris | Friday, 10 November 2006 | 1:07 amDude, you rock. This works great, and was exactly what I was looking for! In particular, the ability to encode a byte array.
[...] http://www.dynamicflash.com/goodies/base64 [...]
Actionscript Classes » Base64 | Saturday, 16 December 2006 | 5:08 am[...] http://www.dynamicflash.com/goodies/base64 [...]
[...] Steve Webster’s Base64 class and just use the result
Iconara » Flex WebServices, problem with <any/> | Tuesday, 25 September 2007 | 8:05 am[...] Steve Webster’s Base64 class and just use the result of Base64.encode(document.toXMLString()) as a parameter to the web service. [...]
[...] Base64 De- and Encoder in Actionscript [...]
Tinkerlog » Blog Archive » Webcam snapshots with Flex3 | Saturday, 03 November 2007 | 6:34 pm[...] Base64 De- and Encoder in Actionscript [...]
Great stuff. If copying and pasting the examples above to
Emma Jones | Tuesday, 11 March 2008 | 12:24 amGreat stuff. If copying and pasting the examples above to test them - just watch the typo in line 1 of the first example about encoding and decoding from String; should be util not utils
Emma: Thanks for letting me know about the typo. I've
Steve | Wednesday, 12 March 2008 | 3:13 pmEmma: Thanks for letting me know about the typo. I’ve just updated the code example
excellent stuff! This does exactly what i needed! Kudo's for you!
erik | Monday, 31 March 2008 | 6:34 pmexcellent stuff! This does exactly what i needed!
Kudo’s for you!
very useful.. thanks!
backz | Tuesday, 13 May 2008 | 4:18 pmvery useful..
thanks!
I was kind of hoping there'd be one in as3corelib;
Karel | Thursday, 15 May 2008 | 7:09 amI was kind of hoping there’d be one in as3corelib; but there isn’t.
Thank you for sharing this
[...] is only available to Flex. Luckily with the richness
import mx.utils.Base64Decoder in Flash CS3 | import Slice.of.Infinity; | Wednesday, 16 July 2008 | 7:06 am[...] is only available to Flex. Luckily with the richness of the web, I found an alternative dynamicflash’s Base 64 Class . However, i still think it’s possible to use Flex library into Flash (AS3) and i found out [...]
[...] http://dynamicflash.com/goodies/base64/ « b+樹數據結構 [...]
岛屿 » Blog Archive » Base64 encoder/decoder class | Sunday, 20 July 2008 | 7:43 am[...] http://dynamicflash.com/goodies/base64/ « b+樹數據結構 [...]
thanx.
sses | Monday, 28 July 2008 | 11:18 pmthanx.