2010-08-08 32 views
2

我正在使用as3crypto库来加密Adobe Air应用程序中的mp3文件。下面的代码运行没有错误,但我意识到只有mp3文件的前几个字节被加密,但不是整个文件。Adob​​e Air使用as3crypto加密mp3文件只加密前几个字节

我不知道是什么问题。有人可能会这么友好,看看我的代码在下面?

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(); 

} 

回答

4

在此期间,我找到了解决方案。如果我替换:

var aes:AESKey = new AESKey(key);

VAR AES:ICipher = Crypto.getCipher(”简单-AES-ECB”,键,Crypto.getPad(” PKCS5“));

它加密整个文件。