最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

android實(shí)現(xiàn)視頻的加密和解密(使用AES)

 更新時(shí)間:2017年05月22日 11:05:26   作者:oldfeel  
本篇文章主要介紹了android實(shí)現(xiàn)視頻的加密和解密(使用AES),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧

java語言進(jìn)行加密解密速度挺慢的。。一個(gè)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

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 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" >

 <Button
  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" />

 <Button
  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" />

</RelativeLayout>

AndroidManifest.xml要添加讀取sd的權(quán)限

復(fù)制代碼 代碼如下:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android動(dòng)態(tài)布局使用詳解

    Android動(dòng)態(tài)布局使用詳解

    這篇文章主要為大家詳細(xì)介紹了Android動(dòng)態(tài)布局的使用方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-07-07
  • Android模擬器

    Android模擬器"Failed To Allocate memory 8"錯(cuò)誤如何解決

    這篇文章主要介紹了Android模擬器"Failed To Allocate memory 8"錯(cuò)誤如何解決的相關(guān)資料,需要的朋友可以參考下
    2017-03-03
  • Android自定義View app更新動(dòng)畫詳解

    Android自定義View app更新動(dòng)畫詳解

    這篇文章給大家分享了Android自定義View app更新動(dòng)畫的相關(guān)代碼以及知識(shí)點(diǎn)內(nèi)容,有興趣的朋友參考學(xué)習(xí)下。
    2018-07-07
  • Android桌面組件App Widget用法入門教程

    Android桌面組件App Widget用法入門教程

    這篇文章主要介紹了Android桌面組件App Widget用法,較為深入淺出的分析了Android桌面組件App Widget的功能、定義及使用技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-09-09
  • Android使用EventBus多次接收消息

    Android使用EventBus多次接收消息

    這篇文章主要為大家詳細(xì)介紹了Android使用EventBus多次接收消息,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-04-04
  • Android仿qq頂部消息欄效果

    Android仿qq頂部消息欄效果

    這篇文章主要介紹了Android仿qq頂部消息欄效果,需要的朋友可以參考下
    2018-04-04
  • Android獲取照片、裁剪圖片、壓縮圖片

    Android獲取照片、裁剪圖片、壓縮圖片

    這篇文章主要為大家詳細(xì)介紹了Android獲取照片、裁剪圖片、壓縮圖片,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-05-05
  • Android禁止橫屏豎屏切換的有效方法

    Android禁止橫屏豎屏切換的有效方法

    這篇文章主要為大家詳細(xì)介紹了Android禁止橫屏豎屏切換的有效方法,具有一定的實(shí)用性,感興趣的小伙伴們可以參考一下
    2016-08-08
  • Android實(shí)現(xiàn)花瓣飄落效果的步驟

    Android實(shí)現(xiàn)花瓣飄落效果的步驟

    這篇文章主要介紹了Android實(shí)現(xiàn)花瓣飄落效果的步驟,幫助大家更好的理解和學(xué)習(xí)使用Android開發(fā),感興趣的朋友可以了解下
    2021-04-04
  • Android音頻可視化開發(fā)案例說明

    Android音頻可視化開發(fā)案例說明

    最近移植Android,當(dāng)Android能夠在設(shè)備上面運(yùn)行之后,首先想到的是讓音頻設(shè)備跑起來?!皼]有聲音,再好的戲也出不來”接下來介紹Android音頻可視化開發(fā)流程
    2012-12-12

最新評(píng)論

岱山县| 阿瓦提县| 大余县| 思茅市| 大足县| 松潘县| 山西省| 锡林郭勒盟| 疏勒县| 工布江达县| 桦南县| 获嘉县| 淳化县| 准格尔旗| 自治县| 定日县| 正镶白旗| 马关县| 昌邑市| 电白县| 荥经县| 墨竹工卡县| 马尔康县| 礼泉县| 高阳县| 梁河县| 墨竹工卡县| 金秀| 库伦旗| 延边| 尉氏县| 霍山县| 斗六市| 灵台县| 海南省| 望城县| 杨浦区| 四子王旗| 泰宁县| 淅川县| 商南县|