没有密钥生成器的河豚文件加密

Blowfish file encryption without keygenerator

如何在不使用使用 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);