如何从URL加密视频和加密的视频保存到设备的SD卡 [英] How to encrypt video from url and save encrypted video to device's SD Card

查看:255
本文介绍了如何从URL加密视频和加密的视频保存到设备的SD卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序必须使用的许多视频文件。所有的视频​​大约总大小为500 MB。所以我决定在第一时间,当应用程序安装,并在该题刻运行我下载视频的背景和加密该视频后保存到设备的SD卡。在以往的视频时我解密​​的视频,并使用它。

In my application I have to use of many video files. Approximately total size of all the video is 500 MB. So I have to decide at the first time when application is install and run at that tike I download videos in background and after encrypting that video saved it to device's SD Card. When ever video is used I decrypt that video and use it.

我决定这是因为所有的视频​​文件是非常重要的,因此该文件的安全性是非常重要的。

I decide this because all the video files are very important, so Security of that file is very important..

我尝试很找到如何加密视频和放大器;它保存到SD卡...

I try very much to find how to encrypt video & save it to SD Card...

最后一件事,我发现,我把下面,但在这种code错误发生权限被拒绝。

Finally one thing I found that I put below but In this code error occurred PERMISSION DENIED.

code:

public class VideoActivity extends Activity 
{
    VideoView video_view;
    MediaController m_controller;
    MediaPlayer mplayer;
    String[] a = {"1","2","3","4","5","6"};

    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


        try {
            main(a);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


    }

        public void writeToFile(String filename, Object object) throws Exception 
        {
            FileOutputStream fos = null;
            ObjectOutputStream oos = null;

            try 
            {
                fos = new FileOutputStream(new File(Environment.getExternalStorageDirectory()+"/corebird1.mp4"));
                oos = new ObjectOutputStream(fos);
                oos.writeObject(object);
                oos.flush();
            }
            catch (Exception e) 
            {
                e.printStackTrace();
            }
            finally 
            {
                if (oos != null) 
                {
                    oos.close();
                }
                if (fos != null) 
                {
                    fos.close();
                }
            }
        }

        public void main(String[] args) throws Exception 
        {
            //
            // Generating a temporary key and stire it in a file.
            //
            SecretKey key = KeyGenerator.getInstance("DES").generateKey();
            writeToFile("secretkey.dat", key);
            Log.d("#######key", String.valueOf(key));

            //
            // Preparing Cipher object for encryption.
            //
            Cipher cipher = Cipher.getInstance("DES");
            cipher.init(Cipher.ENCRYPT_MODE, key);

            //
            // Here we seal (encrypt) a simple string message (a string object).
            //
            SealedObject sealedObject = new SealedObject("THIS IS A SECRET MESSAGE!", cipher);

            //
            // Write the object out as a binary file.
            //
            writeToFile("sealed.dat", sealedObject);
        } 
}

LogCat中:

08-10 12:22:32.430: WARN/System.err(338): java.io.FileNotFoundException: /mnt/sdcard/corebird1.mp4 (Permission denied)
08-10 12:22:32.430: WARN/System.err(338):     at org.apache.harmony.luni.platform.OSFileSystem.openImpl(Native Method)
08-10 12:22:32.459: WARN/System.err(338):     at org.apache.harmony.luni.platform.OSFileSystem.open(OSFileSystem.java:152)
08-10 12:22:32.459: WARN/System.err(338):     at java.io.FileOutputStream.<init>(FileOutputStream.java:97)
08-10 12:22:32.459: WARN/System.err(338):     at java.io.FileOutputStream.<init>(FileOutputStream.java:69)
08-10 12:22:32.459: WARN/System.err(338):     at com.technosoft.video.VideoActivity.writeToFile(VideoActivity.java:71)
08-10 12:22:32.459: WARN/System.err(338):     at com.technosoft.video.VideoActivity.main(VideoActivity.java:99)
08-10 12:22:32.459: WARN/System.err(338):     at com.technosoft.video.VideoActivity.onCreate(VideoActivity.java:54)
08-10 12:22:32.459: WARN/System.err(338):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-10 12:22:32.459: WARN/System.err(338):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
08-10 12:22:32.459: WARN/System.err(338):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
08-10 12:22:32.470: WARN/System.err(338):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
08-10 12:22:32.470: WARN/System.err(338):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
08-10 12:22:32.470: WARN/System.err(338):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-10 12:22:32.470: WARN/System.err(338):     at android.os.Looper.loop(Looper.java:123)
08-10 12:22:32.470: WARN/System.err(338):     at android.app.ActivityThread.main(ActivityThread.java:4627)
08-10 12:22:32.470: WARN/System.err(338):     at java.lang.reflect.Method.invokeNative(Native Method)
08-10 12:22:32.470: WARN/System.err(338):     at java.lang.reflect.Method.invoke(Method.java:521)
08-10 12:22:32.480: WARN/System.err(338):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-10 12:22:32.480: WARN/System.err(338):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-10 12:22:32.480: WARN/System.err(338):     at dalvik.system.NativeStart.main(Native Method)
08-10 12:22:32.480: DEBUG/#######key(338): javax.crypto.spec.SecretKeySpec@69
08-10 12:22:32.510: WARN/System.err(338): java.io.FileNotFoundException: /mnt/sdcard/corebird1.mp4 (Permission denied)
08-10 12:22:32.510: WARN/System.err(338):     at org.apache.harmony.luni.platform.OSFileSystem.openImpl(Native Method)
08-10 12:22:32.520: WARN/System.err(338):     at org.apache.harmony.luni.platform.OSFileSystem.open(OSFileSystem.java:152)
08-10 12:22:32.520: WARN/System.err(338):     at java.io.FileOutputStream.<init>(FileOutputStream.java:97)
08-10 12:22:32.520: WARN/System.err(338):     at java.io.FileOutputStream.<init>(FileOutputStream.java:69)
08-10 12:22:32.520: WARN/System.err(338):     at com.technosoft.video.VideoActivity.writeToFile(VideoActivity.java:71)
08-10 12:22:32.520: WARN/System.err(338):     at com.technosoft.video.VideoActivity.main(VideoActivity.java:116)
08-10 12:22:32.520: WARN/System.err(338):     at com.technosoft.video.VideoActivity.onCreate(VideoActivity.java:54)
08-10 12:22:32.520: WARN/System.err(338):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-10 12:22:32.520: WARN/System.err(338):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
08-10 12:22:32.520: WARN/System.err(338):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
08-10 12:22:32.520: WARN/System.err(338):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
08-10 12:22:32.520: WARN/System.err(338):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
08-10 12:22:32.520: WARN/System.err(338):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-10 12:22:32.520: WARN/System.err(338):     at android.os.Looper.loop(Looper.java:123)
08-10 12:22:32.520: WARN/System.err(338):     at android.app.ActivityThread.main(ActivityThread.java:4627)
08-10 12:22:32.520: WARN/System.err(338):     at java.lang.reflect.Method.invokeNative(Native Method)
08-10 12:22:32.520: WARN/System.err(338):     at java.lang.reflect.Method.invoke(Method.java:521)
08-10 12:22:32.530: WARN/System.err(338):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-10 12:22:32.530: WARN/System.err(338):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-10 12:22:32.530: WARN/System.err(338):     at dalvik.system.NativeStart.main(Native Method)

任何机构对这个错误的解决方案,那么请帮我...

Any body have solution for this error, then please help me...

或者如果妳有任何其他的解决办法或建议随后也u能帮助......我感谢那个......

or If u have any other solution or suggestions then also u can help...I am thankful for that....

我还想方法解密EN code视频和播放的机器人。

I want also method for decrypt the encode video and play that android.

任何机构有任何其他

推荐答案

您所看到的错误无关,加密和一切与文件权限。请问您的应用程序的请求许可使用SD卡?

The error you are seeing has nothing to do with encryption and everything to do with file permissions. Does your app request permission to use the SD card?

其次,为什么DES? DES通常比AES慢很多现代的硬件,并且具有远太短现代使用的密钥。此外,请确保您使用的是GCM,操作的CTR和CBC模式 - 简单的欧洲央行不具有良好的安全性。

Secondly, why DES? DES is usually substantially slower than AES on modern hardware, and has keys that are far too short for modern use. Also, make sure you are using a GCM, CTR or CBC mode of operation - simple ECB does not have good security properties.

一定要明白,要实现经典的DRM方案:任何人都可以访问的设备和应用程序私有目录就能找到密钥文件和解密的视频,或窃取视频在传输过​​程中

Do realize that you are implementing a classic DRM scheme: anyone with access to the device and the application private directory will be able to locate the secret key file and decrypt the video, or steal the video in transit.

这篇关于如何从URL加密视频和加密的视频保存到设备的SD卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆