91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 9KB
    文件類型: .zip
    金幣: 2
    下載: 1 次
    發布日期: 2021-06-18
  • 語言: Java
  • 標簽: Java??加密解密??

資源簡介

進行加密的文檔和加密后的文檔,以及解密后的文檔都需要用戶自己進行創建。

資源截圖

代碼片段和文件信息

package?as;

import?java.io.File;
import?java.io.FileInputStream;
import?java.io.FileOutputStream;
import?java.io.InputStream;
import?java.io.OutputStream;
import?java.security.Key;
import?java.security.SecureRandom;
import?java.util.Scanner;

import?javax.crypto.Cipher;
import?javax.crypto.CipherInputStream;
import?javax.crypto.CipherOutputStream;
import?javax.crypto.KeyGenerator;

import?java.io.BufferedReader;
import?java.io.FileReader;
import?java.io.IOException;
?
public?class?aa?{?
??Key?key;?
??public?aa(String?str)?{?
????getKey(str);//生成密匙?
??}?
??/**?
??*?根據參數生成KEY?
??*/?
??
??public?void?getKey(String?strKey)?{?
????try?{?
????????KeyGenerator?_generator?=?KeyGenerator.getInstance(“DES“);?
????????_generator.init(new?SecureRandom(strKey.getBytes()));?
????????this.key?=?_generator.generateKey();?
????????_generator?=?null;?
????}?catch?(Exception?e)?{?
????????throw?new?RuntimeException(“Error?initializing?SqlMap?class.?Cause:?“?+?e);?
????}?
??}?
?
??/**?
??*?文件file進行加密并保存目標文件destFile中?
??*?
??*?@param?file???要加密的文件?如c:/test/srcFile.txt?
??*?@param?destFile?加密后存放的文件名?如c:/加密后文件.txt?
??*/?
??public?void?encrypt(String?file?String?destFile)?throws?Exception?{?
????Cipher?cipher?=?Cipher.getInstance(“DES“);?
????//?cipher.init(Cipher.ENCRYPT_MODE?getKey());?
????cipher.init(Cipher.ENCRYPT_MODE?this.key);?
????InputStream?is?=?new?FileInputStream(file);?
????OutputStream?out?=?new?FileOutputStream(destFile);?
????CipherInputStream?cis?=?new?CipherInputStream(is?cipher);?
????byte[]?buffer?=?new?byte[1024];?
????int?r;?
????while?((r?=?cis.read(buffer))?>?0)?{?
????????out.write(buffer?0?r);?
????}?
????cis.close();?
????is.close();?
????out.close();?
??}?
??/**?
??*?文件采用DES算法解密文件?
??*?
??*?@param?file?已加密的文件?如c:/加密后文件.txt?
??*?????????*?@param?destFile?
??*?????????解密后存放的文件名?如c:/?test/解密后文件.txt?
??*/?
??public?void?decrypt(String?file?String?dest)?throws?Exception?{?
????Cipher?cipher?=?Cipher.getInstance(“DES“);?
????cipher.init(Cipher.DECRYPT_MODE?this.key);?
????InputStream?is?=?new?FileInputStream(file);?
????OutputStream?out?=?new?FileOutputStream(dest);?
????CipherOutputStream?cos?=?new?CipherOutputStream(out?cipher);?
????byte[]?buffer?=?new?byte[1024];?
????int?r;?
????while?((r?=?is.read(buffer))?>=?0)?{?
????????System.out.println();
????????cos.write(buffer?0?r);?
????}?
????cos.close();?
????out.close();?
????is.close();?
??}?
??
??public?void?Myinterface()?{
System.out.println(“-------------分割線-------------“);
System.out.println();
System.out.println();
System.out.println(“謝謝使用本程序,使用前請將要加密或要解密的文件存放到C盤“);
????System.out.println(“請選擇你要進行的操作,并輸入相應的數字:“);
????System.out.println(“1.選擇文檔進行加密“);
????System.out.println(“2.選擇文檔進行解密“);
????System.out.println(“輸入任意其他數字退出本程序“);
System.out.println();
System.out.println();
System.out.println(“-------------分割線-------------“);
}

?public?static?String?txt2String(Fi

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2019-05-05?15:25??java上機實驗2(對文檔進行加密解密)\
?????目錄???????????0??2019-05-05?15:25??java上機實驗2(對文檔進行加密解密)\as\
?????文件?????????396??2018-09-25?19:38??java上機實驗2(對文檔進行加密解密)\as\.classpath
?????文件?????????378??2018-09-25?19:38??java上機實驗2(對文檔進行加密解密)\as\.project
?????目錄???????????0??2019-05-05?15:25??java上機實驗2(對文檔進行加密解密)\as\.settings\
?????文件??????????63??2018-09-25?20:07??java上機實驗2(對文檔進行加密解密)\as\.settings\org.eclipse.core.resources.prefs
?????文件?????????595??2018-09-25?19:38??java上機實驗2(對文檔進行加密解密)\as\.settings\org.eclipse.jdt.core.prefs
?????目錄???????????0??2019-05-05?15:25??java上機實驗2(對文檔進行加密解密)\as\bin\
?????目錄???????????0??2019-05-05?15:25??java上機實驗2(對文檔進行加密解密)\as\bin\as\
?????文件????????6315??2018-10-07?14:20??java上機實驗2(對文檔進行加密解密)\as\bin\as\aa.class
?????目錄???????????0??2019-05-05?15:25??java上機實驗2(對文檔進行加密解密)\as\src\
?????目錄???????????0??2019-05-05?15:25??java上機實驗2(對文檔進行加密解密)\as\src\as\
?????文件????????6810??2018-10-07?14:20??java上機實驗2(對文檔進行加密解密)\as\src\as\aa.java
?????文件?????????182??2018-10-07?14:24??java上機實驗2(對文檔進行加密解密)\readme.txt

評論

共有 條評論