views:

17

answers:

1

I am using the as3crypto library to encrypt mp3 files in an Adobe Air application. The code below runs without error but I realized that only the first few bytes of the mp3 file are getting encrypted but not the whole file.

I have no idea what’s the problem. Could someone please be so kind and have a look at my code below?

import com.hurlant.crypto.symmetric.AESKey;
import com.hurlant.crypto.symmetric.DESKey;
import com.hurlant.util.Hex;

import mx.controls.Alert;

private static var stream:FileStream;
private static var stream2:FileStream;
private static var file:File;

private var fileToEncrypt:ByteArray;

private function encrypt():void
{
    file = File.documentsDirectory.resolvePath(”airenc/file1.mp3″);

    fileToEncrypt = new ByteArray;

    stream = new FileStream();
    stream.open( file, FileMode.READ );
    stream.readBytes(fileToEncrypt);
    stream.close();

    file = File.documentsDirectory.resolvePath(”airenc/file1-enc.mp3″);

    var key:ByteArray = Hex.toArray(”myEncKey”);
    var aes:AESKey = new AESKey(key);

    aes.encrypt(fileToEncrypt);

    stream2 = new FileStream();
    stream2.open( file, FileMode.WRITE );
    stream2.writeBytes(fileToEncrypt);
    stream2.close();

}
+1  A: 

in the meantime I found the solution. If I replace:

var aes:AESKey = new AESKey(key);

with

var aes:ICipher = Crypto.getCipher(”simple-aes-ecb”, key,Crypto.getPad(”pkcs5″));

It encrypts the whole file.

Max