android视频流加密,android 视频 加密/解密(使用AES)
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)相关推荐
- 解决安卓视频同步(下载)到本地,视频加密解密播放问题
安卓视频加密解密播放问题 出现问题场景:安卓端需要用到视频播放部分,鉴于为防止视频到处拷贝,故有此场景.目前播放部分采用的是ExoPlayer开源播放插件,下载部分采用的是filedownloader ...
- 基于python的文件加密传输_python 利用Crypto进行AES解密加密文件
背景:工作需要,部分数据进行了加密传输,对方使用了AES对密码进行了加密,需要获取到解密的数据. 目标:通过密钥成功解密文件. 关键词:AES_ECB,AES_CBC,Java和Python的AES加 ...
- 一机一码加密软件_加密软件还有哪些功能?
加密软件是办公中常用的一种软件,大家对文件加密也有一定的熟知度,文件除了针对电脑文件防外泄,在日常生活中,我们对文件加密使用的频率较高,所以相对也比较了解,那么加密软件还有哪些功能呢? 一.权限管理 ...
- Android 代码实现视频加密,android实现视频的加密和解密(使用AES)
java语言进行加密解密速度挺慢的..一个6mb左右的文件需要10多秒...等有空了瞅瞅ffmpeg去.. mainactivity.java /** * 视频加密/解密 * * @author ol ...
- Android视频加密那点事儿!
不错,转来备份. 转自:https://blog.csdn.net/shenshibaoma/article/details/79003854 前言 最近有需求要做视频的加密.因为视频下载到本地后,为 ...
- android 大文件加密,如何在android中加密大视频文件
我有一个应用程序,我正在使用该代码来解密已加密的文件.文件位置是"/mnt/sdcard/myfolder/test.mp4". test.mp4文件大小约为20MB.如何在and ...
- android短信加密(发送加密短信,解密本地短信)
短信加密此类功能由于新手学习的需求量较小,所以在网上很少有一些简单的demo供新手参考.笔者做到此处也是花了比较多的时间自我构思,具体的过程也是不过多描述了,讲一下demo的内容.(源码在文章结尾) ...
- android下zip压缩文件加密解密的完美解决方案,Android之zip文件加密解压及进度条的实现...
zip文件的解压可以使用java的zip库,但是没有实现对加密文件的解压功能,这里可以使用zip4j来实现.具体可以参看该文<Android下zip压缩文件加密解密的完美解决方案 http:// ...
- android 文件加密解决方法,一种Android平台的文件快速加密以及解密方法与流程
本发明属于数据安全领域,具体涉及一种Android平台的文件快速加密以及解密方法. 背景技术: 目前移动办公系统极大地提升了企.事业单位的工作效率,而带装有办公应用的智能设备中会存储一些较高机密性的文 ...
最新文章
- 【python】简单实现一个模板引擎
- 模块化数据中心有什么优势?
- ajax 调用后台的方法
- 《Linux4.0设备驱动开发详解》笔记--第三章:Linux下的C编程特点
- Apollo进阶课程㉘丨Apollo控制技术详解——基于模型的控制方法
- 华为软件研发面试题1
- 设计灵感|移动应用的可视化数据图表都是怎么设计的?
- 在sql server中用正则表达式替换html标签,SQL Server中利用正则表达式替换字符串
- 【服务器】WAMP一键安装PHP开发环境
- 分子动力学模拟软件_实惠的分子动力学模拟个人台式机装机和测试
- qca9563修改art区,将2T2R修改为1T1R
- matlab画图线形
- c语言实现小球跳动的效果
- mysql 3389_SQL语句直接开启3389
- 电脑预装Office2016打开Word时点击保存弹出“word无法启动转换器RECOVR32.CNV”对话框问题的修复方法
- 我的理解之JAVA中的4种访问权限
- PROBOT_G603双臂GAZEBO+MoveIt!仿真中配置手眼相机和夹爪
- 百度与谷歌地图瓦片组织方式对比
- bluetooth pdf_这个pdf软件很okk,速来get!
- 【考研英语语法】形容词副词的比较级最高级练习题
热门文章
- 代数笔记-第四章 线性算子
- NT5/NT6上的获取进程全路径
- 搜索引擎中同义词的挖掘及使用
- android studio 光标 输入法,解决IDEA2018.1.5或者Android Studio 3.0版本的输入法不跟随光标问题...
- 三创数据分析题库及个人作答
- 数字视频基础知识简介
- 小胖装机心得 之 耕升显卡造假易迅售后致谢
- PHP 使用 hprose RPC 服务 系列文章之二——Codeigniter3中使用Hprose
- Linux篇 一、香橙派Zero2设置开机连接wifi
- 开启智能手机“新视界”:青橙VOGA V激光投影手机