December 15, 2008 6:17 PM
as3crypto is a feature rich cryptography library for ActionScript 3. I've cooked up versions of CBCMode and ECBMode1 that process the data in chunks so that symmetric encryption / decryption can be pseudo-threaded. The key use case for this is if you want to perform symmetric encryption or decryption on a large block of data in AS3 and do not want the UI to block.


var algo:ISymmetricKey ;

// use AES, DES or any symmetric algorithm
algo = new AESKey(keyBytes);
// OR
algo = new DESKey(keyBytes);

// for ecb, use ECBStreamMode class. 
// Both classes implement ICipherStream
var cbc:CBCStreamMode = new CBCStreamMode(algo);

// if required, output bytes can be consumed here to 
// keep memory usage minimal by accessing cbc.getOutputStream().
outputBytes = cbc.encryptComplete(barr3);


outputBytes = cbc.decryptComplete();

//free mem. Instance is unusable after this call

Download the code here:

CategoryFlex Comment(s)

[1] There are several ways of processing the plaintext or ciphertext when using a symmetric cryptographic algorithm. ECB stands for Electronic codebook and in this mode, the plaintext block of data is simply encrypted with the key. CBC stands for Cipher-block chaining and in this mode, the plaintext is XORed with the previous block's ciphertext before being encrypted with the key. In CBC mode, each ciphertext block is dependant on all plaintext blocks upto that point.

Copyright © 2004-2011 Anirudh Sasikumar. All rights reserved.
Last Updated: December 15, 2008 7:20 PM