11

What would be a best Class for base64 encryption/decryption in Action Script?

cnvzmxcvmcx
  • 1,061
  • 2
  • 15
  • 32
jayarjo
  • 16,124
  • 24
  • 94
  • 138

5 Answers5

13

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.

Corey
  • 5,818
  • 2
  • 24
  • 37
  • 1
    For 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
  • 3
    Flex 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
2

At this link you will find a good Base64 class: http://www.sociodox.com/base64.html

flashkocka
  • 43
  • 5
2

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

Ayoub Kaanich
  • 992
  • 8
  • 20
2

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

NHubben
  • 246
  • 1
  • 5
1

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.

mpdonadio
  • 2,891
  • 3
  • 35
  • 54