I'm trying to encrypt/decrypt files in flex (AIR) using the as3crypto package. the problem is that when attempting to process slightly large files (over 5M) the process time gets ridiculously long and the client freezes (get the "not responding" title) so i tried to go Async and encrypt/decrypt a chunk at a time and interlace it with the frame refresh rate.
the encryption goes smooth, or so it seems, but when i try to decrypt the result back to the original document i get a padding error: "Error: PKCS#5:unpad: Invalid padding value. expected [252], found [152]"
my code is like so (between initiation and finalization):
- the run method gets called repeatedly until the file is completed
- _buffer contains the byte array from the source file
- _result the result
- CHUNK is the bite size of bytes that i process each time
the cipher is initiated as: Crypto.getCipher("aes-ecb", _key, Crypto.getPad("pkcs5"));
public function run(data:Object):Boolean{
} private function processChunk(position:uint,chunk:uint):void{ var buffer:ByteArray = new ByteArray(); buffer.writeBytes(_buffer,position,chunk); if(_action==ENCRYPT){ _aes.encrypt(buffer); }else{ _aes.decrypt(buffer); } _result.writeBytes(buffer); }if((_buffer.length-_position)>CHUNK){ processChunk(_position,CHUNK); _position += CHUNK; var e:ProgressEvent = new ProgressEvent(ProgressEvent.PROGRESS,false,false,_position,_buffer.length); this.dispatchEvent(e); return true; }else if(!_isFinnalized){ processChunk(_position,_buffer.length - _position); this.dispatchEvent(new Event(Event.COMPLETE)); finnalize(); } return false;
help me, please!