0
CipherOutputStream으로 작성된 파일을 읽고 싶을 때 StreamCorruptedExecution이 발생합니다. 파일이 잘 작성되었습니다. 다음은 충돌 마지막 줄에서 발생 코드입니다 :StreamCorruptedExecution Cipher 생성 파일을 읽을 때
file = new File("/sdcard/test.txt");
SecretKey key64 = new SecretKeySpec(new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 }, "Blowfish");
Cipher cipher = Cipher.getInstance("Blowfish");
//Code to write your object to file
cipher.init(Cipher.ENCRYPT_MODE, key64);
SealedObject sealedObject = new SealedObject((Serializable) "TEST", cipher);
CipherOutputStream cipherOutputStream = new CipherOutputStream(new BufferedOutputStream(new FileOutputStream(file)), cipher);
ObjectOutputStream outputStream = new ObjectOutputStream(cipherOutputStream);
outputStream.writeObject(sealedObject);
outputStream.flush();
outputStream.close();
//now try to read it again
CipherInputStream cipherInputStream = new CipherInputStream(new BufferedInputStream(new FileInputStream(file)), cipher);
ObjectInputStream inputStream = new ObjectInputStream(cipherInputStream); //<== this line crashes with StreamCorruptedExecution
안전하지 않은 ECB 모드 (기본값은''Blowfish''를'Cipher'를위한 알고리즘으로 사용함)에 있습니다. 복어는 오래되었고 천천히, AES는 요즘 추천됩니다. –