android视频加密解密
来源:互联网 发布:caffe.io.transformer 编辑:程序博客网 时间:2024/05/21 06:49
4M的视频加密了一分钟。时间是硬伤。
package com.example.videoencrypt;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;import java.security.InvalidKeyException;import java.security.NoSuchAlgorithmException;import javax.crypto.Cipher;import javax.crypto.CipherInputStream;import javax.crypto.CipherOutputStream;import javax.crypto.NoSuchPaddingException;import javax.crypto.spec.SecretKeySpec;import android.net.Uri;import android.os.Bundle;import android.app.Activity;import android.view.Menu;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.MediaController;import android.widget.Toast;import android.widget.VideoView;/** * @author henry_wang * date:2015-11-24 * time: 下午10:24:45 */public class MainActivity extends Activity {private static final String filePath="/sdcard/20151123_233943.mp4";private static final String outPath="/sdcard/encrypt_henry.mp4";private static final String inPath="/sdcard/decrpt_henry.mp4";MediaController mc;@Overrideprotected 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);VideoView video=(VideoView) findViewById(R.id.video);mc=new MediaController(this);String uri="http://english-video.oss-cn-hangzhou.aliyuncs.com/whlei.mp4";video.setVideoURI(Uri.parse(inPath));video.setMediaController(mc);mc.setMediaPlayer(video);video.requestFocus();video.start();encryptButton.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View view) {try {encrypt();Toast.makeText(getApplicationContext(), "henry_wang==加密完成", 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() {@Overridepublic void onClick(View view) {try {decrypt();Toast.makeText(getApplicationContext(), "henry_wang==解密完成", Toast.LENGTH_SHORT).show();} catch (InvalidKeyException e) {e.printStackTrace();}catch (NoSuchAlgorithmException e) {e.printStackTrace();}catch (NoSuchPaddingException e) {e.printStackTrace();}catch (IOException e) {e.printStackTrace();}}});}protected static void encrypt() throws NoSuchAlgorithmException,NoSuchPaddingException, InvalidKeyException, IOException {FileInputStream fis=new FileInputStream(filePath);FileOutputStream fos=new FileOutputStream(outPath);SecretKeySpec sks=new SecretKeySpec("MyDifficultPassw".getBytes(),"AES");Cipher cipher=Cipher.getInstance("AES");cipher.init(Cipher.ENCRYPT_MODE, sks);CipherOutputStream cos=new CipherOutputStream(fos, cipher);int b;byte[] d=new byte[8];while ((b=fis.read(d))!=-1) {cos.write(d,0, b);}cos.flush();cos.close();fis.close();}protected void decrypt() throws NoSuchAlgorithmException, NoSuchPaddingException,InvalidKeyException, IOException {FileInputStream fis=new FileInputStream(outPath);FileOutputStream fos=new FileOutputStream(inPath);SecretKeySpec sks=new SecretKeySpec("MyDifficultPassw".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();}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {getMenuInflater().inflate(R.menu.main, menu);return true;}}
0 0
- android视频加密解密
- Android 视频&文件,加密 解密
- 完成的一个android视频加密解密播放的案例
- Android 加密解密字符串
- Android 加密解密字符串
- Android 加密解密
- Android 加密解密字符串
- Android 加密解密
- Android DES加密解密
- android 加密解密
- android des 加密解密
- Android 加密解密
- android 加密 解密
- android Base64加密解密
- Android RSA加密解密
- Android RSA加密解密
- Android RSA加密解密
- android Base64加密解密
- GBDT(MART) 迭代决策树入门教程 | 简介
- dhroid框架介绍之一
- Hdoj.2058 The sum problem【数列】 2015/11/24
- poj3259Wormholes【SPFA判负环】
- 用TFIDF给特征词赋权值
- android视频加密解密
- hadoop rpc基础
- 进程/多线程/同步任务/异步任务/串行队列/并行队列
- Java中的网络编程复习
- 统计nginx某个请求
- crucible3.x +fisheye3.x 安装和破解
- angularJS学习之路(二十九)---控制器的别名使用 和它的作用域的确定
- 开启技术博客
- 控制---人之永恒探索