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

📄 encrypt.java~13~

📁 java中加密解密的用法全例子!这个对于爱好java的朋友对加密解密的学习很有用
💻 JAVA~13~
字号:
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(String filePath) throws Exception {

        //岞奐尞傪宍惉偡傞
        byte[] keykb = {
                       28, -1, 64, 64, 71, 106, 1, 72, -31, 47, -108, -75, -110,
                       78, 33, 105};
        SecretKeySpec secretKeySpec = new SecretKeySpec(keykb, "BlowFish");
        //埫崋壔偟偨屻偺僼傽僀儖偺僷僗丅
        try {

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

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

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

            //the file(bnavie_exp_enc.xml) encrypt into "bo\\encrypt"
            String path = "bo"+fenge+"encrypt"+fenge+"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 + -