Android利用Java对视频进行加密

package sf;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;

public class Util {
	static byte XOR = 0X12;
    static MappedByteBuffer buffer=null;
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		encode();
	}

	@SuppressWarnings("resource")
	public static void encode() {
        try {
            File file = new File("D:/VID_20140728_163015.3gp");
            boolean  fs= file.exists();
            boolean  fss = file.isFile();
            System.out.println(fs);
            System.out.println(fss);
            if(file.exists()&&file.isFile()){
                
                buffer=new RandomAccessFile("D:/VID_20140728_163015.3gp","rw").getChannel().map(FileChannel.MapMode.READ_WRITE, 0, 10);
                int sum=0;
                long t1=System.currentTimeMillis();
                for(int i=0;i<10;i++){
                   byte sd = 'a';
                   byte src= (byte) (buffer.get(i)+sd);
                   System.out.println("before :"+src);
                   src = (byte)(src^XOR);
                   System.out.println("after :"+src);
                   buffer.put(i,src);//修改Buffer中映射的字节的值   
                   //new RandomAccessFile(file, mode)
                }
                buffer.force();
                buffer.clear();
                
                long t=System.currentTimeMillis()-t1;
                System.out.println("sum:"+sum+"  time:"+t);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }


	}

}
只能加密头文件信息,也就是
buffer=new RandomAccessFile("D:/VID_20140728_163015.3gp","rw").getChannel().map(FileChannel.MapMode.READ_WRITE, 0, 10);
就是最后两位只能是0到 long(xxx) 就是加密头信息视频不能被视频,不能打开,如果最后两位写成long position   long(xxx)
比如:
<pre name="code" class="java">buffer=new RandomAccessFile("D:/VID_20140728_163015.3gp","rw").getChannel().map(FileChannel.MapMode.READ_WRITE, 23223, 1024);
那么视频这一段将会出现小片的模糊,但是还是可以打开的。

                
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值