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

📄 encrypt.java~7~

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

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

public class Encrypt {
  private String fenge = java.io.File.separator;
  public void Encrypt() throws Exception{
    //XML僼傽僀儖偺僷僗傪妉摼偡傞丅
    XMLPath xPt = new XMLPath();
    String xmlPath = null;
    try {
      xmlPath = xPt.getXmlPath();
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }
    //岞奐尞傪宍惉偡傞
    byte[] keykb = {
        28, -1, 64, 64, 71, 106, 1, 72, -31, 47, -108, -75, -110, 78, 33, 105};
    SecretKeySpec secretKeySpec = new SecretKeySpec(keykb, "BlowFish");
    //埫崋壔偡傞慜偺僼傽僀儖偺僷僗丅
    xmlPath="bo\\unencrypt";
    String encrypt = xmlPath + fenge +  "bnavie_exp.xml";
    //埫崋壔偟偨屻偺僼傽僀儖偺僷僗丅
    String encrypted = xmlPath + fenge + "bnavie_exp_enc.xml";
    try {

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

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

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

      //the file(bnavie_exp_enc.xml) encrypt into "bo\\encrypt"
      String path="bo\\encrypt\\bnavie_exp_enc.xml";
      FileOutputStream fileOutputStream = null;
      fileOutputStream = new FileOutputStream(path);

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

⌨️ 快捷键说明

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