cipheroutputstream.java

来自「纯java AES实现」· Java 代码 · 共 50 行

JAVA
50
字号
package com.jrijndael.io;import java.io.*;import com.jrijndael.JRijndael;public class CipherOutputStream {        //The underlying BufferedOutputStream instance    private BufferedOutputStream bos;        //The underlying block cipher instance    private JRijndael algorithm;        /** Creates a new instance of CipherOutputStream */    public CipherOutputStream(FileOutputStream fos, String passphrase, int keylength) {        //Create a new instance of the BufferedOutputStream        bos = new BufferedOutputStream(fos);                //Create a new instance of the block cipher        algorithm = new JRijndael();                //Initialize the block cipher        algorithm.generateKey(passphrase, keylength);    }        /** Encrypts then writes a byte array to the BufferedOutputStream */    public void write(byte[] b) throws IOException {        //Encrypt the supplyed byte array        byte[] cipherText = algorithm.encryptByteArray(b);                //Write the encrypted bytes to the BufferedOutputStream        bos.write(cipherText);    }        /** Flushes the BufferedOutputStream */    public void flush() throws IOException {        //Flush the BufferedOutputStream        bos.flush();    }        /** Clears the cipher, then closes the BufferedOutputStream */    public void close() throws IOException {        //Clear the block cipher        algorithm.clear();                //Close the BufferedOutputStream        bos.close();    }}

⌨️ 快捷键说明

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