encrypt.java~9~

来自「java中加密解密的用法全例子!这个对于爱好java的朋友对加密解密的学习很有用」· JAVA~9~ 代码 · 共 50 行

JAVA~9~
50
字号
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 {

        //岞奐尞傪宍惉偡傞
        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 path before encrypt丅
        String encrypt = "bo\\unencrypt" + fenge + "bnavie_exp.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 + =
减小字号Ctrl + -
显示快捷键?