开发者

How to encrypt/decrypt an FLV using Flash

开发者 https://www.devze.com 2023-04-13 07:40 出处:网络
I\'m working on an Windows application(created in .NET) which one of its functions is to play local FLVs using SWF components.

I'm working on an Windows application(created in .NET) which one of its functions is to play local FLVs using SWF components.

Now I need to create an encryption application to make sure those FLVs cannot be played freely, only the SWF player will know how to decrypt that file(using a key received from .NET app).

I was thinking of creating an Air app to encode my flvs (maybe ByteArray class?), using some algorithm to shuffle/unshuffle characters based in a key string.

My main need is how to encode/decode a file using Air/Flash. I tried some times, just trying to load a FLV, convert to ByteArray, then save the new FLV, but this new FLV won't pl开发者_如何学编程ay. Opening into Notepad++, I noticed the file have a few characters before it's FLV header.

Anyone knows how to do that correctly? Thanks!


only the SWF player will know how to decrypt that file.

If somebody has access to the SWF, they can decompile it, and find out how to decrypt your FLVs.

A better way would be to encrypt them with something like AES, then get the key from a server.

If you're not worried about people decompiling your SWF, just do anything that will cause media players to fail to open it.

Yes, you would use ByteArray to modify your FLV.

About the extra bytes, you shouldn't be "converting" to ByteArray, it should already be in that format when you receive it. It sounds like you somehow had it in a String and you used writeUTF, which writes the length at the beginning.


Here is a example of what I achieved throught my experiences and googling. Works perfectly.

    public function Main():void 
    {           
        us.load(new URLRequest("file.ext"))
        us.addEventListener(Event.COMPLETE, onVideoLoaded);
    } 

    private function onVideoLoaded(e:Event):void
    {
        var bytes:ByteArray = new ByteArray();  
        us.readBytes(bytes, bytes.length, us.bytesAvailable);

        bytes = encrypt(bytes);         
        saveFile(bytes);
    }

    private function saveFile(bytes:ByteArray):void
    {           
        var fileStream:FileStream = new FileStream();
        fileStream.open(File.desktopDirectory.resolvePath("filename.ext"), FileMode.WRITE);
        fileStream.writeBytes(bytes, 0, bytes.length);
        fileStream.close();

        fileStream.addEventListener(OutputProgressEvent.OUTPUT_PROGRESS, onCompleteFile);
    }


    private function encrypt(bytes:ByteArray):ByteArray 
    {
        var i:int = bytes.length;
        while (i--)
        {
            bytes[i] += 128;
        }

        return bytes;
    }

Using ROT128 to encrypt a file, more info here.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号