Java 无密钥生成器的Blowfish文件加密

Java 无密钥生成器的Blowfish文件加密,java,encryption,blowfish,secret-key,Java,Encryption,Blowfish,Secret Key,如何在不使用使用Blowfish算法的KeyGenerator的情况下加密文件 这是我的部分代码 Cipher cipher = Cipher.getInstance("Blowfish"); cipher.init(Cipher.ENCRYPT_MODE, key); FileInputStream fis = new FileInputStream(plain); FileOutputStream fos = new FileOutputStream(copy); CipherOutput

如何在不使用使用Blowfish算法的KeyGenerator的情况下加密文件

这是我的部分代码

Cipher cipher = Cipher.getInstance("Blowfish");
cipher.init(Cipher.ENCRYPT_MODE, key);
FileInputStream fis = new FileInputStream(plain);

FileOutputStream fos = new FileOutputStream(copy);
CipherOutputStream out2 = new CipherOutputStream(fos, cipher);
byte[] buffer = new byte[1024];
while (fis.read(buffer)>=0) {
    out2.write(buffer);
}

如果您有密钥,可以使用如下SecretKeySpec提供:

byte[] key = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
SecretKey keySpec = new SecretKeySpec(key, "Blowfish");
Cipher cipher = Cipher.getInstance("Blowfish");
cipher.init(Cipher.ENCRYPT_MODE, keySpec);

谢谢你的回复,现在,我正在浏览一个要使用JFileChooser()加密的文件;我现在的问题是将此文件传递给加密方法,并提示用户使用inputDialog输入加密密钥,请问如何实现此目的?@NehemiahLimo从未使用静态硬编码密钥。如果用户要输入密码,则使用带有随机salt的密钥派生函数