简体   繁体   English

如何使用Flash加密/解密FLV

[英]How to encrypt/decrypt an FLV using Flash

I'm working on an Windows application(created in .NET) which one of its functions is to play local FLVs using SWF components. 我正在使用Windows应用程序(在.NET中创建),该应用程序的功能之一是使用SWF组件播放本地FLV。

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). 现在,我需要创建一个加密应用程序以确保那些FLV不能​​自由播放,只有SWF播放器才知道如何解密该文件(使用从.NET应用程序收到的密钥)。

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. 我当时正在考虑创建一个Air应用程序来对我的flv(也许是ByteArray类?)进行编码,并使用某种算法来对键字符串中的字符进行混洗/取消混排。

My main need is how to encode/decode a file using Air/Flash. 我的主要需求是如何使用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 play. 我尝试了几次,只是尝试加载FLV,转换为ByteArray,然后保存新的FLV,但是此新的FLV无法播放。 Opening into Notepad++, I noticed the file have a few characters before it's FLV header. 打开Notepad ++,我注意到该文件在FLV标头之前有几个字符。

Anyone knows how to do that correctly? 有人知道如何正确执行此操作吗? Thanks! 谢谢!

only the SWF player will know how to decrypt that file. 只有SWF播放器才会知道如何解密该文件。

If somebody has access to the SWF, they can decompile it, and find out how to decrypt your FLVs. 如果有人可以访问SWF,则可以对其进行反编译,并了解如何解密FLV。

A better way would be to encrypt them with something like AES, then get the key from a server. 更好的方法是使用AES之类的方法对它们进行加密,然后从服务器获取密钥。

If you're not worried about people decompiling your SWF, just do anything that will cause media players to fail to open it. 如果您不担心人们会反编译您的SWF,请执行任何会导致媒体播放器无法打开它的操作。

Yes, you would use ByteArray to modify your FLV. 是的,您将使用ByteArray来修改您的FLV。

About the extra bytes, you shouldn't be "converting" to ByteArray , it should already be in that format when you receive it. 关于多余的字节,您不应该“转换”为ByteArray ,接收时它应该已经是这种格式了。 It sounds like you somehow had it in a String and you used writeUTF , which writes the length at the beginning. 听起来您好像以某种方式将其包含在String并且使用了writeUTF ,它会在开头写入长度。

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 . 使用ROT128加密文件,更多信息在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM