What would be a best Class for base64 encryption/decryption in Action Script?
5 Answers
Adobe has two utils for this - Base64Encoder & Base64Decoder. Both are located in the mx.utils package. Although, I had to track them down here - encoder & decoder.
The usage would be something like:
var bmd:BitmapData = myBitmap.bitmapData;
var ba:ByteArray = bmd.getPixels(new Rectangle(0,0,bmd.width,bmd.height));
var b64:Base64Encoder = new Base64Encoder();
b64.encodeBytes(ba);
trace(b64.toString());
Similarly, 'b64.encode' would encode a String rather than a ByteArray.
Both the encoder and decoder add their respective results to an internal buffer. So, you just have to use 'toString' to return the current buffer.

- 5,818
- 2
- 24
- 37
-
1For some reason, the [documentation on their site](http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/utils/Base64Encoder.html) is incomplete. Fortunately, the correct documentation shows up under FlashBuilder's auto-complete feature. – BlueRaja - Danny Pflughoeft Mar 21 '13 at 17:37
-
I would go with this hurlant package also. – Andrey Popov Apr 08 '14 at 08:26
-
+1! works out of the box, no need to bundle any special files. Note: if you don't see the mx package in FlashDevelop, see this [question](http://stackoverflow.com/questions/524893/flashdevelop-why-does-code-completion-not-work-with-mx-controls). – rustyx Jan 19 '15 at 13:52
-
3Flex has been moved to the apache servers. Here are the new paths to files Сorey mentioned: [Base64Encoder](https://git-wip-us.apache.org/repos/asf/flex-sdk/repo?p=flex-sdk.git&a=blob&f=frameworks/projects/framework/src/mx/utils/Base64Encoder.as&hb=refs/heads/master) [Base64Decoder](https://git-wip-us.apache.org/repos/asf/flex-sdk/repo?p=flex-sdk.git&a=blob&f=frameworks/projects/framework/src/mx/utils/Base64Decoder.as&hb=refs/heads/master) – Alexander Ushakov Aug 14 '15 at 14:41
At this link you will find a good Base64 class: http://www.sociodox.com/base64.html

- 43
- 5
blooddy_crypto
claims (according to it's benchmark) to have a faster base64 encoder/decoder than the mx.utils
one.

- 992
- 8
- 20
This one seems to have some legs/supporters: http://garry-lachman.com/2010/04/21/base64-encoding-class-in-actionscript-3/

- 246
- 1
- 5
Most of the packages that I have seen that include one as a support function use the one that is credited to Steve Webster. I do not know which package this started out in, but it appears in several libraries, including the as3crypto lib on Google Code.

- 2,891
- 3
- 35
- 54