⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unencrypt.java~8~

📁 java中加密解密的用法全例子!这个对于爱好java的朋友对加密解密的学习很有用
💻 JAVA~8~
字号:
package encryptandunencrypt;

import java.io.*;
import javax.crypto.*;
import javax.crypto.spec.SecretKeySpec;

public class UnEncrypt {
  private String fenge = java.io.File.separator;
  public void UnEncrypt() throws Exception {
    //僼傽僀儖傪僥僗僩偟偰懚嵼偡傞偐偳偆偐丅
    TestFile testFile = new TestFile();
    boolean flag = testFile.Testbnavie_exp_enc();
    if (!flag) {
      return;
    }

    //XML僼傽僀儖偺僷僗傪妉摼偡傞丅
    XMLPath xPt = new XMLPath();
    String xmlPath = null;
    try {
      xmlPath = xPt.getXmlPath();
    }
    catch (Exception ex) {
      ex.printStackTrace();
      System.exit(0);
    }

    //岞奐尞傪宍惉偡傞
    byte[] keykb = {
        28, -1, 64, 64, 71, 106, 1, 72, -31, 47, -108, -75, -110, 78, 33, 105};
    SecretKeySpec secretKeySpec = new SecretKeySpec(keykb, "BlowFish");

    //the file name of unencrypt丅
    xmlPath="bo:\\encrypt";
    String encrypt = xmlPath + fenge + "bnavie_exp.xml";
    //the file encrypted丅
    String encrypted = xmlPath + fenge +"bnavie_exp_enc.xml";

    try {
      //埫崋壔偺曽幃傪憂寶偟偰弶婜壔偡傞丅
      Cipher cipher = null;
      cipher = Cipher.getInstance("BlowFish");
      cipher.init(Cipher.DECRYPT_MODE, secretKeySpec);

      //憂寶偺埫崋壔偡傞偺偼晧偗偰帪悽偵崌偆丅
      FileInputStream fileInputStream = null;
      fileInputStream = new FileInputStream(encrypted);

      //CipherInputStream懳徾傪憂寶偡傞丅
      CipherInputStream cipherInputStream = new CipherInputStream(
          fileInputStream, cipher);

      //強偼枾側寢壥傪棟夝偡傞丅
      FileOutputStream fileOutputStream = null;
      fileOutputStream = new FileOutputStream(encrypt);

      //晧偗傞偙偲傪摼偰帪悽偵崌偆丅
      int b = 0;
      while ( (b = cipherInputStream.read()) != -1) {
        fileOutputStream.write(b);
      }

      //偡傋偰偺桝弌擖傪暵嵔偟偰棳傟傞丅
      fileInputStream.close();
      cipherInputStream.close();
      fileOutputStream.close();

      //嶍彍偟偰埫崋壔偟偨屻偺僥儞億儔儕僼傽僀儖丅
      xmlPath="bo:\\unencrypt";
      String xmlField = xmlPath + fenge + "bnavie_exp_enc.xml";
      File xmlFile = new File(xmlField);
      xmlFile.delete();
    }
    catch (Exception ex) {
      ex.printStackTrace();
      throw ex;
    }
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -