暗号化されたStringとその解読キーのマップを含む.serファイルを作成しています(これは最善の方法ではありませんが、プロジェクト)私は次にシリアル化を使用して暗号化します:暗号化された.serファイルを復号化してStreamCorruptedExceptionをスローする
private void encryptKeysFile() throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, IOException{
SecretKey key64 = new SecretKeySpec(new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 }, "Blowfish");
Cipher cipher = Cipher.getInstance("Blowfish");
cipher.init(Cipher.ENCRYPT_MODE, key64);
File keysFile = new File(System.getProperty("src"),fileName);
SealedObject sealedObject = new SealedObject(keysFile, cipher);
CipherOutputStream cipherOutputStream = new CipherOutputStream(new BufferedOutputStream(new FileOutputStream(fileName)), cipher);
ObjectOutputStream outputStream = new ObjectOutputStream(cipherOutputStream);
outputStream.writeObject(sealedObject);
outputStream.close();
}
オブジェクトは、ドライブ上のファイルに書き戻されます。 I読者のファイルとそれを復号化する別の方法:これらのメソッドがエラーを実行している
private File dencryptKeysFile() throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, IOException, ClassNotFoundException, BadPaddingException{
SecretKey key64 = new SecretKeySpec(new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 }, "Blowfish");
Cipher cipher = Cipher.getInstance("Blowfish");
cipher.init(Cipher.DECRYPT_MODE, key64);
CipherInputStream cipherInputStream = new CipherInputStream(new BufferedInputStream(new FileInputStream(fileName)),cipher);
ObjectInputStream inputStream = new ObjectInputStream(cipherInputStream);
SealedObject sealedObject = (SealedObject)inputStream.readObject();
inputStream.close();
File keysFile =(File)sealedObject.getObject(cipher);
this.keysFile = keysFile;
return keysFile;
}
ザ・:
java.io.StreamCorruptedException: invalid stream header: E0F0DDB8
at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
at java.io.ObjectInputStream.<init>(Unknown Source)
at mainClasses.Encrypter.dencryptKeysFile(Encrypter.java:180)
at mainClasses.Encrypter.main(Encrypter.java:214)
をファイルにスローされますが読み込まれていません。 Encrypter.java:180 =
ObjectInputStream inputStream = new ObjectInputStream(cipherInputStream);
@SteelToeいいえ、そうではありません。これは、異なるストリームヘッダー値と全く異なるコードを参照します。この質問とは関係ありません。 – EJP