Hallo,
Ich möchte einen Datenstrom dechiffrieren und nutze daher den CipherInputStream folgendermaßen:
Das komische Verhalten ist nun, dass die Dateilänge 16 Bytes ist. Wenn ich die abfrage durch "file.length()" erhalte ich auch 16. Nach der Anweisung:
sind diese 16 Byte plötzlich weg. "is.available()" liefert nun 0.
Wo sind diese Bytes hin?
Und was mache ich hier falsch?
Danke!
Ich möchte einen Datenstrom dechiffrieren und nutze daher den CipherInputStream folgendermaßen:
Java:
public void decryptFile(String AESKey, File file, File output) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IOException {
System.out.println(AESKey);
byte[] key = (AESKey).getBytes("UTF-8");
MessageDigest sha = MessageDigest.getInstance("MD5");
key = sha.digest(key);
key = Arrays.copyOf(key, 16);
SecretKeySpec secretKeySpec = new SecretKeySpec(key, "AES");
Cipher cipher2 = Cipher.getInstance("AES");
cipher2.init(Cipher.DECRYPT_MODE, secretKeySpec);
System.out.println("file.length() == "+file.length());
CipherInputStream is = new CipherInputStream(new FileInputStream(file), cipher2);
System.out.println(is.available());
FileOutputStream os = new FileOutputStream(output);
copy(is, os);
is.close();
os.close();
}
private void copy(CipherInputStream is, FileOutputStream os) throws IOException {
System.out.println("avl: "+is.available());
int i;
byte[] b = new byte[1024];
while((i=is.read(b))!=-1) {
System.out.println("out: "+i);
os.write(b, 0, i);
}
}
Das komische Verhalten ist nun, dass die Dateilänge 16 Bytes ist. Wenn ich die abfrage durch "file.length()" erhalte ich auch 16. Nach der Anweisung:
Java:
CipherInputStream is = new CipherInputStream(new FileInputStream(file), cipher2);
Wo sind diese Bytes hin?
Und was mache ich hier falsch?
Danke!
Zuletzt bearbeitet von einem Moderator: