java语言进行加密解密速度挺慢的。。一个6MB左右的文件需要10多秒。。。等有空了瞅瞅ffmpeg去。。

MainActivity.java

/**

* 视频加密/解密

*

* @author oldfeel

*

*         Created on: 2014-2-17

*/

public class MainActivity extends Activity {

// 原文件

private static final String filePath = "/sdcard/DCIM/Camera/VID_20140217_144346.mp4";

// 加密后的文件

private static final String outPath = "/sdcard/DCIM/Camera/encrypt.mp4";

// 加密再解密后的文件

private static final String inPath = "/sdcard/DCIM/Camera/decrypt.mp4";

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

Button encryptButton = (Button) findViewById(R.id.main_encrypt);

Button DecryptButton = (Button) findViewById(R.id.main_decrypt);

encryptButton.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

try {

encrypt();

Toast.makeText(getApplicationContext(), "加密完成",

Toast.LENGTH_SHORT).show();

} catch (InvalidKeyException e) {

e.printStackTrace();

} catch (NoSuchAlgorithmException e) {

e.printStackTrace();

} catch (NoSuchPaddingException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

}

});

DecryptButton.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

try {

decrypt();

Toast.makeText(getApplicationContext(), "解密完成",

Toast.LENGTH_SHORT).show();

} catch (InvalidKeyException e) {

e.printStackTrace();

} catch (NoSuchAlgorithmException e) {

e.printStackTrace();

} catch (NoSuchPaddingException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

}

});

}

/**

* Here is Both function for encrypt and decrypt file in Sdcard folder. we

* can not lock folder but we can encrypt file using AES in Android, it may

* help you.

*

* @throws IOException

* @throws NoSuchAlgorithmException

* @throws NoSuchPaddingException

* @throws InvalidKeyException

*/

static void encrypt() throws IOException, NoSuchAlgorithmException,

NoSuchPaddingException, InvalidKeyException {

// Here you read the cleartext.

FileInputStream fis = new FileInputStream(filePath);

// This stream write the encrypted text. This stream will be wrapped by

// another stream.

FileOutputStream fos = new FileOutputStream(outPath);

// Length is 16 byte

SecretKeySpec sks = new SecretKeySpec("MyDifficultPassw".getBytes(),

"AES");

// Create cipher

Cipher cipher = Cipher.getInstance("AES");

cipher.init(Cipher.ENCRYPT_MODE, sks);

// Wrap the output stream

CipherOutputStream cos = new CipherOutputStream(fos, cipher);

// Write bytes

int b;

byte[] d = new byte[8];

while ((b = fis.read(d)) != -1) {

cos.write(d, 0, b);

}

// Flush and close streams.

cos.flush();

cos.close();

fis.close();

}

static void decrypt() throws IOException, NoSuchAlgorithmException,

NoSuchPaddingException, InvalidKeyException {

FileInputStream fis = new FileInputStream(outPath);

FileOutputStream fos = new FileOutputStream(inPath);

SecretKeySpec sks = new SecretKeySpec("oldfeelwasverynb".getBytes(),

"AES");

Cipher cipher = Cipher.getInstance("AES");

cipher.init(Cipher.DECRYPT_MODE, sks);

CipherInputStream cis = new CipherInputStream(fis, cipher);

int b;

byte[] d = new byte[8];

while ((b = cis.read(d)) != -1) {

fos.write(d, 0, b);

}

fos.flush();

fos.close();

cis.close();

}

}

activity_main.xml

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:paddingBottom="@dimen/activity_vertical_margin"

android:paddingLeft="@dimen/activity_horizontal_margin"

android:paddingRight="@dimen/activity_horizontal_margin"

android:paddingTop="@dimen/activity_vertical_margin"

tools:context=".MainActivity" >

android:id="@+id/main_encrypt"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentTop="true"

android:layout_centerHorizontal="true"

android:layout_marginTop="147dp"

android:text="Encrypt" />

android:id="@+id/main_decrypt"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignRight="@+id/main_encrypt"

android:layout_centerVertical="true"

android:text="Decrypt" />

AndroidManifest.xml要添加读取sd的权限

android第三方视频播放加密,android 视频 加密/解密(使用AES)相关推荐

  1. android第三方图标库,Android 第三方库AgentWeb的使用

    Android 第三方库AgentWeb的使用 一:前言 Android开发经常会用到WebView,用于加载网页.系统自带的WebView性能和流畅度都一般,AgentWeb是一款第三方的WebVi ...

  2. android第三方应用商店,Android第三方应用商店成长迅猛

    在移动互联网保持高速发展的今天,随着Android市场份额不断提升,基于Android操作系统应用的第三方应用商店也在迅速成长中,其最具成长代表性的量值即为内容分发量,其所勾勒出的的发展曲线也很好的证 ...

  3. android第三方打开文件,Android第三方文件选择器aFileChooser使用方法详解

    aFileChooser是android平台上的一个第三方文件选择器,其在github上的项目主页是:https://github.com/iPaulPro/aFileChooser aFileCho ...

  4. android第三方 视频播放器

    推荐一个不错的第三播放器: 1.IjkPlayer/MediaPlayer+TextureView,支持列表,完美切换全屏.小窗口的Android视频播放器 地址:https://github.com ...

  5. android万能播放器,Android万能视频播放器05-音视频同步

    1.概念 由于视频播放器中音频和视频是分别播放和渲染的,就会出现声音和画面不同步的现象.为了使同一时刻声音和画面的一致性,我们就需要音视频同步来实现,这就是音视频同步. 2.播放时间 2.1.音频播放 ...

  6. android 第三方登录界面,Android App集成第三方登录与换肤指南

    Android App集成第三方登录与换肤指南 文档编辑 概述 本文主要是介绍了如何通过开源框架快速支持QQ和微信登录,并介绍了如何实现app快速换肤 QQ登录接入 APP要支持QQ登录,需要先到腾讯 ...

  7. android第三方launcher,目前Android平台最好的Launcher

    由于Blackberry Priv无法Root,也无法刷其他的Room,因此可以折腾的也就只有Launcher了.其实Priv自带Launcher就已经很不错了,尤其是对于某些应用,上滑以预览的方式打 ...

  8. android第三方闹钟开发,Android获取第三方闹钟的闹铃信息

    收集闹铃信息 闹铃时间,闹铃备注信息 闹铃引起系统变化的点: 1. Send Notification (正点闹钟可以设置不发送) 2. Play audio 闹铃信息结构体 ClockInfo{ S ...

  9. android弹幕视频播放器,Android直播播放器 弹幕使用总结

    今日科技快讯作者简介 本篇是 小河马 的第二篇投稿,分享了他学习开源播放器的过程.希望能对大家有所帮助. 小河马的博客地址:http://www.jianshu.com/u/14354bcb0e09介 ...

  10. android第三方菜单设计,Android菜单设计指南(上)

    菜单设计快速预览 •    任何指令的选项菜单只针对当前的操作. •    任何指令的(弹出式)文本菜单只针对当前被选中项. •    优先排序频繁使用的指令(or功能). •    将最重要的指令( ...

最新文章

  1. android sdk版本控制,1. 统一SDK版本管理配置
  2. linux查看内存cpu占用
  3. Linux下查看CPU/内存/硬盘的shell命令
  4. linux下磁盘是硬盘吗,肿么确定linux系统上的硬盘哪个是主盘
  5. 过程质量保证PQA的几个关键方面
  6. button按钮跳转JS代码
  7. error: field 'b' has imcomplete type
  8. 电商系统下单时商品库存和销售状态如何处理
  9. 基本算法研究1-冒泡排序算法测试
  10. 剑指Offer - 面试题26. 树的子结构(双重递归)
  11. Win10怎么禁用系统更新服务 Win10禁用系统更新服务教程
  12. Centos7 重启网卡
  13. tcp/ip源代码(17)——ip_fragment
  14. 程序员必读的入门到大牛高效书单
  15. 如何看懂luac -l -l 命令
  16. PS(Photoshop)去水印的方法
  17. 那些年陪伴我们搬砖的心灵的音乐
  18. 2014网络红人排行榜
  19. 决战面试(二)智力题考察
  20. Java方法创建及调用--------06

热门文章

  1. 挑战程序设计竞赛:三角形
  2. 移动html5 滑动 zepto,移动端使用zepto编写的滑动事件
  3. ttl接地是高电平还是低电平_数电练习题
  4. Java jar 如何防止被反编译
  5. Fortran95基础知识学习
  6. python alphago_资源 | 如何通过 Python 打造一款简易版 AlphaGo?
  7. 软件那么多,恢复数据还靠它
  8. Struts2框架中为什么要继承ActionSupport类,以及实现过程
  9. JAVE 视音频转码
  10. 浅谈安全攻防场景下面的安全检测